Fatal Error:Maximum execution time of 120 seconds is exceeded - php

Error:
https://i.stack.imgur.com/ZZQkW.jpg
Fatal Error:Maximum execution time of 120 seconds is exceeded
The page loads very slowly.
The goal was to insert data and file to the table. But something does not let it. I will use my code as an example in this case.
So the user types their data here:
<?php
require_once $_SERVER["DOCUMENT_ROOT"] . "/tonevre/data_inc/functions.php";
use tonevre\general;
use tonevre\VideoUpload;
if(isset($_POST["addVideo"])) {
$videoUpload = new VideoUpload;
$response = $videoUpload->addVideo();
}
?>
<label>Name your video!</label>
<ul>
<input type="text" name="title" placeholder="Title" required>
<label>Description</label>
<input type="text" name="descrip" placeholder="Tell the viewers about your video" required>
<label>Upload your file</label>
<input type="file" name="image" required>
<button type="submit" name="addVideo">UPLOAD</button>
This data goes here (addVideo is a method from the class VideoUpload):
public function addVideo(){
#This will insert the data to the table called vidup
ini_set('max_execution_time', 0);
$title = $_POST["title"] ? $_POST["title"] : "";
$descrip = $_POST["descrip"] ? $_POST["descrip"] : "";
$image = $_FILES["image"]["name"] ? $_FILES["image"]["name"] : "";
$sql = "INSERT INTO vidup (title, descrip, image) VALUES (?, ?, ?)";
$paramType = "sss";
$paramValue = array(
":title" => $title,
":descrip" => $descrip,
":image" => $image
);
$this->ds->prepare($sql, $paramType, $paramValue);
$this->ds->execute($sql, $paramType, $paramValue);
// if the title is empty echo the error message
if(empty($title)) {
$response["status"] = "error";
$response["message"] = "Please enter a title";
return $response;
}
if(empty($paramValue)) {
$response["status"] = "error";
$response["message"] = "There is a problem";
return $response;
}
I will also mention this, for more details:
public function prepare($query, $paramType, $paramArray)
{
$stmt = $this->conn->prepare($query);
$this->bindQueryParams($stmt, $paramType, $paramArray);
$stmt->execute();
return $stmt;
header("location: ../header.php");
}
public function bindQueryParams($stmt, $paramType, $paramArray = array())
{
ini_set('memory_limit', '-1');
$paramValueReference[] = &$paramType;
for ($i = 0; $i < count($paramArray); $i++) {
$paramValueReference[] = &$paramArray[$i];
}
call_user_func_array(array(
$stmt,
'bind_param'
), $paramValueReference);
}
I couldn't find any solid enough explanation for the cause. A good explanation would help me and others in the future. Thank you.

Related

How to INSERT an array of uploaded filenames into a table and later display them?

I am working on a project where each item could have multiple images, I created a form that would accept the images and store them into an array. The problem is whenever I try inserting the images into a table row in the database it displays an error:
"Array to string conversion"
How can I fix this? And also how do I fetch each images on another page from the same database table. Below is my code.
-Form code
<form method="post" enctype="multipart/form-data" >
<input required type="text" name="name">
<input required type="text" name="location">
<input required type="text" name="status">
<select required name="category">
<option>Category</option>
<option value="construct">Construction</option>
<option value="promgt">Project Development</option>
<option value="archdesign">Architectural Designs</option>
</select>
<textarea required class="form-control" name="descrip" rows="5"></textarea>
<input style="text-align:left" type="file" name="imgs[]" multiple>
<button type="submit" name="submit" formaction="addaction.php">Add Project</button>
</form>
-Addaction.php code
<?php
$db=mysqli_connect("localhost","root","dbpassword","dbname");
if(!empty($_FILES['imgs']['name'][0])){
$imgs = $_FILES['imgs'];
$uploaded = array();
$failed = array();
$allowed = array('jpg', 'png');
foreach($imgs['name'] as $position => $img_name){
$img_tmp = $imgs['tmp_name'][$position];
$img_size = $imgs['size'][$position];
$img_error = $imgs['error'][$position];
$img_ext = explode('.',$img_name);
$img_ext = strtolower(end($img_ext));
if(in_array($img_ext, $allowed)) {
if($img_error === 0){
if($img_size <= 500000) {
$img_name_new = uniqid('', true) . '.' . $img_ext;
$img_destination = 'img/'.$img_name_new;
if(move_uploaded_file($img_tmp, $img_destination)){
$uploaded[$position] = $img_destination;
}else{
$failed[$position] = "[{$img_name}] failed to upload";
}
}else{
$failed[$position] = "[{$img_name}] is too large";
}
}else{
$failed[$position] = "[{$img_name}] error";
}
}else{
$failed[$position] = "[{$img_name}] file extension";
}
}
if(!empty($uploaded)){
print_r($uploaded);
}
if(!empty($failed)){
print_r($failed);
}
}
if(isset($_POST['submit'])){
$name = $_POST['name'];
$location = $_POST['location'];
$status = $_POST['status'];
$descrip = $_POST['descrip'];
$category = $_POST['category'];
$img_name_new = $_FILES['imgs']['name'];
if ($db->connect_error){
die ("Connection Failed: " . $db->connect_error);
}
$sql_u = "SELECT * FROM projects WHERE name='$name'";
$sql_e = "SELECT * FROM projects WHERE category='$category'";
$res_u = mysqli_query($db, $sql_u);
$res_e = mysqli_query($db, $sql_e);
if (mysqli_num_rows($res_u) && mysqli_num_rows($res_e) > 0) {
echo "<div style='margin: 0 80px' class='alert alert-danger' role='alert'> Error. Item Already exists </div>";
header("refresh:3 url=add.php");
}else{
$sql_i = "INSERT INTO items (name, location, status, descrip, imgs, category) VALUES ('$name','$location','$status,'$descrip','$img_name_new','$category')";
}
if (mysqli_query($db, $sql_i)){
echo "Project Added Successfully";
}else{
echo mysqli_error($db);
}
$db->close();
}
?>
$img_name_new = $_FILES['imgs']['name'] is an array of one or more image names.
You will need to decide how you wish to store the array data as a string in your database.
Here are a couple of sensible options, but choosing the best one will be determined by how you are going to using this data once it is in the database.
implode() it -- $img_name_new = implode(',', $_FILES['imgs']['name']);
json_encode() it -- $img_name_new = json_encode($_FILES['imgs']['name']);
And here is my good deed for the year...
Form Script:
<?php
if (!$db = new mysqli("localhost", "root", "", "db")) { // declare and check for a falsey value
echo "Connection Failure"; // $db->connect_error <-- never show actual error details to public
} else {
if ($result = $db->query("SELECT name FROM items")) {
for ($rows = []; $row = $result->fetch_row(); $rows[] = $row);
$result->free();
?>
<script>
function checkName() {
var names = '<?php echo json_encode($rows); ?>';
var value = document.forms['project']['name'].value;
if (names.indexOf(value) !== -1) { // might not work on some old browsers
alert(value + ' is not a unique name. Please choose another.');
return false;
}
}
</script>
<?php
}
?>
<form name="project" method="post" enctype="multipart/form-data" onsubmit="return checkName()">
Name: <input required type="text" name="name"><br>
Location: <input required type="text" name="location"><br>
Status: <input required type="text" name="status"><br>
Category: <select required name="category">
<?php
if ($result = $db->query("SELECT category, category_alias FROM categories")) {
while ($row = $result->fetch_assoc()) {
echo "<option value=\"{$row['category']}\">{$row['category_alias']}</option>";
}
}
?>
</select><br>
<textarea required class="form-control" name="descrip" rows="5"></textarea><br>
<input style="text-align:left" type="file" name="imgs[]" multiple><br>
<button type="submit" name="submit" formaction="addaction.php">Add Project</button>
</form>
<?php
}
*notice that I have made a separate category table for validation.
Submission Handling Script: (addaction.php)
<?php
if (isset($_POST['submit'], $_POST['name'], $_POST['location'], $_POST['status'], $_POST['descrip'], $_POST['category'], $_FILES['imgs']['name'][0])) {
$paths = [];
if (!empty($_FILES['imgs']['name'][0])) {
$imgs = $_FILES['imgs'];
$allowed = array('jpg', 'png');
foreach($imgs['name'] as $position => $img_name){
$img_tmp = $imgs['tmp_name'][$position];
$img_size = $imgs['size'][$position];
$img_error = $imgs['error'][$position];
$img_ext = strtolower(pathinfo($img_name)['extension']);
if (!in_array($img_ext, $allowed)) {
$errors[] = "File extension is not in whitelist for $img_name ($position)";
} elseif ($img_error) {
$errors[] = "Image error for $img_name ($position): $image_error";
} elseif ($img_size > 500000) {
$errors[] = "Image $image_name ($position) is too large";
} else {
$img_destination = 'img/' . uniqid('', true) . ".$img_ext";
if (!move_uploaded_file($img_tmp, $img_destination)) {
$errors[] = "Failed to move $img_name ($position) to new directory";
} else {
$paths[] = $img_destination;
}
}
}
}
if (!empty($errors)) {
echo '<ul><li>' , implode('</li><li>', $errors) , '</li></ul>';
} elseif (!$db = new mysqli("localhost", "root", "", "db")) { // declare and check for a falsey value
echo "Connection Failure"; // $db->connect_error <-- never show actual error details to public
} elseif (!$stmt = $db->prepare("SELECT COUNT(*) FROM categories WHERE category = ?")) {
echo "Prepare Syntax Error"; // $db->error; <-- never show actual error details to public
} elseif (!$stmt->bind_param("s", $_POST['category']) || !$stmt->execute() || !$stmt->bind_result($found) || !$stmt->fetch()) {
echo "Category Statement Error"; // $stmt->error; <-- never show actual error details to public
} elseif (!$found) {
echo "Category Not Found - Project Not Saved";
} else {
$stmt->close();
$cs_paths = (string)implode(',', $paths);
// Set the `name` column in `items` to UNIQUE so that you cannot receive duplicate names in database table
if (!$stmt = $db->prepare("INSERT INTO items (name, location, status, category, descrip, imgs) VALUES (?,?,?,?,?,?)")) {
echo "Error # prepare"; // $db->error; // don't show to public
} elseif (!$stmt->bind_param("ssssss", $_POST['name'], $_POST['location'], $_POST['status'], $_POST['category'], $_POST['descrip'], $cs_paths)) {
echo "Error # bind"; // $stmt->error; // don't show to public
} elseif (!$stmt->execute()) {
if ($stmt->errno == 1062) {
echo "Duplicate name submitted, please go back to the form and change the project name to be unique";
} else {
echo "Error # execute" , $stmt->error; // $stmt->error; // don't show to public
}
} else {
echo "Project Added Successfully";
}
}
}

trouble in inserting record to database using PHP mysqli oops [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am using PHP mysqli to access and insert record to database and also prepared statements but somewhere there is an error i couldn't figure out.. pointing out the mistake will be very much helpful
mailer.php
<?php
class Submit {
const DB = 'localhost',
USER = 'test',
PASS = '123456',
DB_NAME = 'testing';
private $mysql;
public function __construct() {
$this->mysql = new mysqli(self::DB , self::USER , self::PASS , self::DB_NAME);
if ($this->mysql->connect_errno) {
echo "Error: " . $this->mysql->connect_error;
echo "<br>";
echo "Error code: " . $this->mysql->connect_errno;
}
}
public function addRecord($record) {
$status = false;
$query = "INSERT INTO mytable (name,message) VALUES (?,?)";
$stmt = $this->mysql->prepare($query);
if ( $stmt ) {
$stmt->bind_param('ss', $record->name , $record->message);
if ($stmt->execute()) {
$status = ($stmt->affected_rows == 1) ? true : false;
$stmt->fetch_object();
$stmt->close();
}
}
return $status;
}
}
$submit = new Submit();
$result = null;
if (isset($_POST['submit']) ) {
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';
$result = $submit->addRecord($name,$message);
if ($result) {
echo "Message Saved";
}
}
Also i am using ajax call from an external file containing a form and scripts within that
index.php
<!DOCTYPE html>
<html>
<head>
<title>Contact Form | PHP, AJAX and MySQL</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<br /><br />
<div class="container" style="width:500px;">
<form id="submit_form">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" />
<br />
<label for="message">Message</label>
<textarea name="message" id="message" class="form-control"></textarea>
<br />
<input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit" />
<span id="error_message" class="text-danger"></span>
<span id="success_message" class="text-success"></span>
</form>
</div>
</body>
</html>
<script>
jQuery(function($){
$('form#submit_form').submit(function(e){
e.preventDefault();
var name = $(this).find('#name').val(),
message = $(this).find('#message').val();
if(name == '' || message == '') {
$('#error_message').html("All Fields are required");
}
else {
$('#error_message').html('');
$.ajax({
url:"mailer.php",
method:"POST",
data:{
name: name,
message: message
},
success:function(data){
$("form").trigger("reset");
$('#success_message').fadeIn().html(data).fadeOut(3000);
}
});
}
});
});
</script>
You are giving 2 parameters to your addRecord() method, but it expects only 1. But, it seems it expects an object which you are not initializing so I adjusted it, so it takes the two parameters you are giving it.
public function addRecord($name, $message) {
$status = false;
$query = "INSERT INTO mytable (name,message) VALUES (?,?)";
$stmt = $this->mysql->prepare($query);
if ( $stmt ) {
$stmt->bind_param('ss', $name , $message);
if ($stmt->execute()) {
$status = $stmt->affected_rows === 1;
}
}
return $status;
}
Also I removed some unnecessary steps in the method:
$status = ($stmt->affected_rows == 1) ? true : false;
$status = $stmt->affected_rows === 1;
The comparison itself will return a boolean, so no need to use an explicit structure.
$stmt->fetch_object();
$stmt->close();
Fetching the object without ever using it is a waste.
When leaving the scope of the method, the garbage collector will unset the stmt.
Code to test the function:
class Submit {
const DB = 'localhost',
USER = 'test',
PASS = '123456',
DB_NAME = 'testing';
private $mysql;
public function __construct() {
$this->mysql = new mysqli(self::DB , self::USER , self::PASS , self::DB_NAME);
if ($this->mysql->connect_errno) {
echo "Error: " . $this->mysql->connect_error;
echo "<br>";
echo "Error code: " . $this->mysql->connect_errno;
}
}
public function addRecord($name, $message) {
$status = false;
$query = "INSERT INTO mytable (name,message) VALUES (?,?)";
$stmt = $this->mysql->prepare($query);
if ( $stmt ) {
$stmt->bind_param('ss', $name , $message);
if ($stmt->execute()) {
$status = $stmt->affected_rows === 1;
}
}
return $status;
}
}
$submit = new Submit();
$result = null;
$name = "dsfdsf";
$message = "message";
$result = $submit->addRecord($name,$message);
var_dump($result); // bool(true)

Difficulty uploading & updating images to directory/MySQL using PHP

I can upload images as a serialized array no problem, but all I need is to store the raw filename string on my database and I'm not sure where to start editing my pre-existing code get this to work. This should be easier but as a PHP novice I can't get it to work.
Essentially, I want to be able to upload images then display them on the front end of my site doing something like this:
<img src="img/<php echo $config->photo_a ?>"/>
My existing code is:
<?php
//connect to db //
session_start();
include('../config.php');
// check for login to use //
if (!$user->authenticated)
{
header('Location: login.php');
die();
}
//post form as array using class photo_loader//
if (isset($post->form_action))
{
$a = new photo_loader(false, $db);
$a->name = $post->name;
$image_files = array();
for ($i=1; $i<10; $i++)
{
if (isset($_FILES['file'.$i]['name']) && $_FILES['file'.$i]['name'] != "")
{
$img = new upload($_FILES['file'.$i], M_ENV_SITE_URL, M_ENV_SITE_ROOT);
$img->set_upload_target("/img/");
$n = $img->do_upload();
if (!$n)
{
$err = "Image file ".$i." too big or wrong file type.";
}
else
{
$image_files[] = $n;
$img->batchResize("/img/", "/img/", $n, array("320x240", "800x600"));
}
}
}
if (empty($image_files)) $err = "You must include at least one image.";
$a->value = $image_files;
if (!$err)
{
$a->create();
$succ = "Success!";
}
}
?>
Using a simple form like this:
<form action="" method="post" enctype="multipart/form-data">
<div class="control-group"><label for="file" class="control-label">Attach Slideshow Images:</label><div class="controls">
<?php
for ($i=1;$i<10;$i++)
{
echo "<input name=\"file".$i."\" type=\"file\" value=\"\" id=\"file".$i."\" />";
} ?>
</div></div>
<input type="hidden" name="name" value="photo_a">
<div class="form-actions">
<input type="submit" name="form_action" class="btn btn-large btn-primary" value="Save" />
</div>
</form>
and photo_loader.class.php looks like this:
<?php
class photo_loader
{
private $properties;
var $db;
function __construct($id, $dbase)
{
$this->db = $dbase;
if (is_numeric($id))
{
$sql = sprintf(
"SELECT * FROM minty_config
WHERE ID=%d",
$this->db->clean($id)
);
$result = $this->db->query($sql);
$fields = $this->db->fetch_array($result);
foreach ($fields as $k => $v)
{
$this->properties[$k] = $v;
}
$this->value = unserialize($this->value);
}
}
function __get($k)
{
return $this->properties[$k];
}
function __set($k, $v)
{
$this->properties[$k] = $v;
}
function update()
{
$sql = sprintf(
"UPDATE minty_config SET
name='%s',
value='%s'
WHERE ID=%d",
$this->db->clean($this->name),
serialize($this->value),
$this->ID
);
$this->db->query($sql);
}
function create()
{
$sql = sprintf(
"INSERT INTO minty_config
(name, value)
VALUES('%s', '%s')",
$this->db->clean($this->name),
unserialize($this->value)
);
$this->db->query($sql);
}
function delete()
{
$sql = sprintf(
"DELETE FROM minty_config
WHERE ID=%d",
$this->ID
);
$this->db->query($sql);
}
}
?>
I presume I need to remove the $image_files = array(); section but I don't know what to replace with! Seemingly keep making mistakes and returning blank pages with errors or not uploading the image. I can't see it being too diffuclt but I presume I'm going the wrong way about it. Many thanks in advance!!

jQuery-File-Upload blueimp PHP-MySQL-database-update data

how to make changes to the data 'title' and 'description' after the image is loaded, for example, add a button to "change"?
This is all done up and running
https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration
Here is my code, but here it is necessary to make a new method to "upgrade" and synchronize it with html:
html:
name <br /><input name="title[]" value="{%=file.title||''%}">
description<br /> <input name="description[]" value="{%=file.description||''%}">
php:
public function update($print_response = true) {
$response = parent::update(false);
foreach ($response as $name => $update) {
if ($update) {
$sql = 'update set `title`=? ,`description`=? '
.$this->options['db_table'].'` WHERE `name`=?';
$query = $this->db->prepare($sql);
$query->bind_param('sss',$file->title,$file->description, $name);
$query->execute();
}
}
return $this->generate_response($response, $print_response);
}
JS?

Using HTTP to Add files [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm using Luracast's Restler Framework which is great. But I was wondering if someone could tell me how I can upload files through HTTP.
I was using a simple HTML Form to POST data to the API, and trying to grabe the file information from $_FILES, but i'm not getting anything.
Here is my super simple form
<form method="post" action="index.php/product">
<p>
<label>Product name</label>
<input name="product_name" />
</p>
<p>
<label>MSRP Price</label>
<input name="msrp_price" />
</p>
<p>
<label>Category</label>
<input name="category_name" />
</p>
<p>Teir Pricing</p>
<p>
<label>Price</label>
<input name="price[]" />
</p>
<p>
<label>Buy Range Min</label>
<input name="buy_range_min[]" />
</p>
<p>
<label>Buy Range Max</label>
<input name="buy_range_max[]" />
<p>
<label>Price</label>
<input name="price[]" />
</p>
<p>
<label>Buy Range Min</label>
<input name="buy_range_min[]" />
</p>
<p>
<label>Buy Range Max</label>
<input name="buy_range_max[]" />
</p>
<p>
<label>Image</label>
<input type="file" name="image" />
</p>
<input type="submit" />
</form>
Here is my class that works with Restler
<?
class Product {
public $dp;
private $DBH;
public $highest_max = 0;
function __construct() {
$host = 'localhost';
$db_name = '';
$db_user = '';
$db_password = '';
try {
$this ->DBH = new PDO('mysql:host='.$host.';dbname='.$db_name, $db_user, $db_password);
// Line takes care of error reporting.
$this->DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $e) {
// return $e->getMessage();
return 'Sorry there was an issue';
}
} // end function
function get($id=NULL) {
if (is_null($id)) {
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM products";
$data = array('product_id' => $id);
$STH = $this->DBH->prepare($sql);
// binds the params
$STH->execute($data);
// wHAT TYPE OF DATA WE ARE GRABING
$STH->setFetchMode(PDO::FETCH_ASSOC);
// GO TRough IT ALL
while($row = $STH->fetch()) {
$rows[] = $row;
} // end while
return $rows;
} // end if
else {
$sql = "SELECT * FROM products WHERE product_id = :product_id";
$data = array('product_id' => $id);
$STH = $this->DBH->prepare($sql);
// binds the params
$STH->execute($data);
// wHAT TYPE OF DATA WE ARE GRABING
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetch();
return $row;
} // end else
} // end function
function add_teir_pricing($price, $buy_range_min, $buy_range_max, $product_id) {
// check to see if the min is higher then this max
if ($buy_range_min >= $buy_range_max) {
throw new RestException(417,'Your min price teir must be smaller then your max' );
} // end if
elseif ($buy_range_min <= $this->highest_max) {
throw new RestException(417,'One of your minimum price teirs cannot overlap with another.' );
} // end if
$this->highest_max = $buy_range_max;
# the data we want to insert
$data = array( 'price' => $price, 'buy_range_min' => $buy_range_min, 'buy_range_max' => $buy_range_max, 'product_id' => $product_id );
$sql = "INSERT INTO teir_pricing (price, buy_range_min, buy_range_max, product_id, created) value (:price, :buy_range_min, :buy_range_max, :product_id, NOW())";
$STH = $this->DBH->prepare($sql);
$STH->execute($data);
} // end function
function post($product_id=NULL,$member_id, $product_name, $upc_code, $sku, $global_trade_item_number, $link_to_product_reviews,
$url_to_product,
$msrp_price,
$category_name, $price, $buy_range_min, $buy_range_max) {
// ADD PRODUCT
if (!isset($product_name)) {
$error = true;
// $errors['message'][] = 'Mising a product_name';
throw new RestException(417,'Mising a product_name');
} // end if
if (!isset($msrp_price)) {
$error = true;
// $errors['message'][] = 'Mising a msrp_price';
throw new RestException(417,'Missing MSRP price');
} // end if
if (!isset($category_name)) {
$error = true;
// $errors['message'][] = 'You must assign a category_name to this product';
throw new RestException(417,'You must assign a category_name to this product');
} // end if
// We still need to grab the member id from the key when this is added.
$member_id = 1;
$product_data = array('member_id' => $member_id,
'product_name' => $product_name,
'upc_code' => $upc_code,
'sku' => $sku,
'global_trade_item_number' => $global_trade_item_number,
'link_to_product_reviews' => $link_to_product_reviews,
'url_to_product' => $url_to_product,
'msrp_price' => $msrp_price,
'category_name' => $category_name);
$sql = "INSERT INTO
products
(product_name,
upc_code,
sku,
global_trade_item_number,
link_to_product_reviews,
url_to_product,
member_id,
msrp_price,
created,
category_name)
VALUES
(:product_name,
:upc_code,
:sku,
:global_trade_item_number,
:link_to_product_reviews,
:url_to_product,
:member_id,
:msrp_price,
NOW(),
:category_name
)";
$q = $this->DBH->prepare($sql);
$q->execute($product_data);
$product_id = $this->DBH->lastInsertId();
foreach($price as $key => $value) {
Product::add_teir_pricing($price[$key], $buy_range_min[$key], $buy_range_max[$key], $product_id);
} // end foreach
$response = array('product_id' => $product_id, 'status' => 'success', 'message' => 'Your product has been added', 'files' => $_FILES);
return $response;
} // end function
function upload_image($_FILES) {
return $_FILES;
} // end function
} // end class
?>
You can only upload files if the form data is sent as multipart/form-data. The default is application/x-www-form-urlencoded.
From the specification:
<FORM action="http://server.com/cgi/handle"
enctype="multipart/form-data"
method="post">

Categories