Back to this after a long day migrating a window application to an SCO UNIX box ...
This file upload is driving me crazy. I had it working with a FF uncaught error ... I decided to modify code and got rid of the error and with it, everything else.
I changed my code to simplify the PHP side of things and when I print the content of $_FILES, I get
Code:
Array ( [image] => Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) ) )
As you can see, I am getting the error "4 - File not uploaded". Notice that name, tmp_name, type and size are all blank.
Here is my new PHP code
Code:
if (isset($_POST['fileframe']))
{
$result = 'ERROR!!!';
$result_msg = '';
print_r($_FILES);
echo '<br /><br />';
echo 'Will check for _FILES[image] ... <br />';
echo '_FILE[image][name]['.$_POST['action'].'] is set to: '.$_FILES['image']['name'][$_POST['action']].'<br />';
if (isset($_FILES['image']['name'][$_POST['action']])) // file was send from browser
{
$filex = $_FILES['image']['name'][0];
echo 'File image is set ... to: '.$filex.'<br />';
echo 'File image error set ... to: '.$_FILES['image']['error'][0].'<br />';
if ($_FILES['image']['error'][0] == UPLOAD_ERR_OK) // no error
{
echo 'No error uploading thumbnail ...<br />';
$filename = $_FILES['image']['name'][$_POST['action']]; // file name
move_uploaded_file($_FILES['image']['tmp_name'][$_POST['action']], $upload_dir.'/'.$filename);
// main action -- move uploaded file to $upload_dir
$result = 'OK';
} elseif ($_FILES['image']['error'][$_POST['action']] == UPLOAD_ERR_INI_SIZE) {
$result_msg = 'Image is too large!<br />';
} else {
$result_msg .= $_FILES['image']['error'][$_POST['action']];
}
// you may add more error checking
// see [URL unfurl="true"]http://www.php.net/manual/en/features.file-upload.errors.php[/URL]
// for details
} else {
echo '_files[image] is not set ... <br />';
}
echo 'result_msg set to : '.$result_msg.'<br />';
// This is a PHP code outputing Javascript code.
echo '<html><head><title>-</title></head><body>';
echo '<script language="JavaScript" type="text/javascript">'."\n";
echo 'var parDoc = window.parent.document;';
// this code is outputted to IFRAME (embedded frame)
// main page is a 'parent'
$imgID = 'image'; $imgStat = 'imgstatus'; $newimg = 'newimage';
if($_POST['action'] > 0)
{
$imgID = 'thumbnail';
$imgStat = 'thumbnailstatus';
$newimg = 'newthumbnail';
}
if ($result == 'OK')
{
// Simply updating status of fields and submit button
echo 'parDoc.getElementById("'.$imgStat.'").value = "Successfully Uploaded!";';
echo 'parDoc.getElementById("saveform").style.display = "block";';
// echo 'parDoc.getElementById("'.$imgID.'").value = "'.$filename.'";';
echo 'parDoc.getElementById("'.$newimg.'").value = "'.$filename.'";';
}
else
{
echo 'parDoc.getElementById("'.$imgStat.'").value = "ERROR: '.$result_msg.'";';
}
echo "\n".'</script></body></html>';
exit(); // do not go futher
} elseif (isset($_POST['target'])) {
if($_POST['category'] < 1) { $result_msg .= 'Please select a category!<br />'; }
if($_POST['name'] == '') { $result_msg .= 'Please enter a name!<br />'; }
if($_POST['price'] < .01) { $result_msg .= 'Please enter a price!<br />'; }
if($_POST['description'] == '') { $result_msg .= 'Please enter a description!<br />'; }
}
As far as the JS function jsUpload, here is the code
Code:
function jsUpload(upload_field,img)
{
// this is just an example of checking file extensions
// if you do not need extension checking, remove
// everything down to line
// upload_field.form.submit();
var re_text = /\.jpg|\.gif|\.png/i;
var filename = upload_field.value;
var status = 'imgstatus';
if(img > 0) status = 'thumbnailstatus';
/* Checking file type */
if (filename.search(re_text) == -1)
{
document.getElementById(status).value = "File must be jpg, gif or png!";
return false;
}
document.getElementById('action').value = img;
document.getElementById(status).value = "uploading file...";
upload_field.disabled = true;
upload_field.form.submit();
return true;
}
I love the fact that the code works on your end. This means that the logic is functional and that I am missing something very simple.
It might be worth mentioning that the routine responsible for processing the submitted form is included by index.php as it checks for parameters and determines proper course of action. I am going to set my form action to go directly to the PHP script and bypass index.php ... I do not think this is the root cause of my problem but worth a try.
Thanks,
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.