Jump to content

How do I get $_FILES['photo'] to pass to AJAX.php file?


robertlob

Recommended Posts

Among other inputs, my HTML form contains an input file selector for an image (jpeg).

 

In non-AJAX, the php file opens the $_FILES['photo'] and retrieves the tmp_name, name, size, type, and error values and posts the image data to a mysql database table correctly.

 

In the AJAX version, the ..._xml.php file appears to work, but the image values are all null or empty.

 

using:

 

if ($_FILES['photo']) {

$img = $_FILES['photo']['tmp_name];

$img_name = $_FILES['photo']['name'];

$img_size = $_FILES['photo']['size'];

$img_type = $_FILES['photo']['type'];

$img_error = $_FILES['photo']['error'];

 

$binary_data = addslashes(fread(fopen($img, "rb"), filesize($img)));

$sql = "INSERT INTO binary_data VALUES

          ('','$binary_data','$img_name','$img_size','$img_type','$rec')";

 

$r = mysql_query($sql, $dbc);

if (mysql_affected_rows($dbc) == 1) {

  //do something

}

 

...where '' is the auto incremented db record, and $rec is defined elsewhere as a key to a record in a related table.

 

The only data that makes it to the database is the auto incremented record number and the $rec value. None of the image data appears. No error shows, and AJAX reports the image added correctly in the <result> area of the form.

 

Do I need to use a different syntax in the ...xml.php file? When tested the non-AJAX way, the data is properly added to the db using this code. I haven't been able to find any examples addressing using $_FILES() for images in a ..._xml.php file, so any assistance would be appreciated.

 

Thank you,

Robert

 

 

 

 

 

Link to comment
Share on other sites

Ok - It does not show a "required field" error, when I add that error code.

 

But it does show a $img_error as 1 on the ..._xml.php results, which means that the file exceeds the max_file_size allowed by php.ini.

 

On the .php handler, it shows a $img_error of 0 or no error for the same file.

 

The file is only 44KB

The max_file_upload_size in php.ini is 4M (increased from default 2M)

 

What gives? anybody know?

Link to comment
Share on other sites

Thank you for the link.

 

I am wondering if this solution requires a separate form from other form elements that can be handled by AJAX, or if it can be worked into the single form? I have not had time yet to study on it, so maybe that answer will be obvious once I look closer at the work around.

 

Appreciate your help,

Robert

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.