robertlob Posted October 7, 2009 Share Posted October 7, 2009 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 Quote Link to comment Share on other sites More sharing options...
robertlob Posted October 7, 2009 Author Share Posted October 7, 2009 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? Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 9, 2009 Share Posted October 9, 2009 you cannot uppload files via AJAX, sorry, you have to do a little work around using an iframe. linked below. http://geekswithblogs.net/rashid/archive/2007/08/01/Create-An-Ajax-Style-File-Upload.aspx Quote Link to comment Share on other sites More sharing options...
robertlob Posted October 9, 2009 Author Share Posted October 9, 2009 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 Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 9, 2009 Share Posted October 9, 2009 no separate form needed, just follow the work around and you'll see. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.