arianhojat Posted May 23, 2007 Share Posted May 23, 2007 Hello all, I am not sure why but I have had this problem for a while and havent really been able to solve it. A really simple php upload script works in IE but not in FF. FF just comes back to the page as if there is no POST information. For example code below will output when landing on the page, it outputs: count:0 NOT SUBMITTED, 5-23-2007 16:13:35 and when trying to post the upload via the html submit button, it outputs immediately: count:0 NOT SUBMITTED, 5-23-2007 16:13:54 but it SHOULD have POST data?, count should be > 0, and it should output SUBMITTED if enctype="multipart/form-data" is removed, it will post the data (of course no upload data though): count:3 data=Array ( [filename] => Array ( [0] => blc.gif [1] => ) [MAX_FILE_SIZE] => 100000000 [submitForm] => Submit ) SUBMITTING <?php echo 'count:'. count($_POST) .'<br/>'; if( count($_POST) > 0 ) { echo 'data='; print_r($_POST); } if( isset($_POST['submitForm']) ) { echo "SUBMITTING<br/>" ; foreach ($_FILES["filename"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $path_parts = pathinfo(__file__); $dir = $path_parts['dirname']."\\uploads"; $tmp_name = $_FILES["filename"]["tmp_name"][$key]; $name = $_FILES["filename"]["name"][$key]; move_uploaded_file($tmp_name, "$dir\\$name"); echo "tmp_name=$tmp_name, name=$name, type=$type, size=$size<br/>" ; } else echo 'error:'.$error; } }//submitted else echo "NOT SUBMITTED, ". date('n-j-Y G:i:s') .'<br/>'; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TEST</title> </head> <body> <form name="upload" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>"> File to upload: <br/> <input type="file" name="filename[]" value="Upload1" /> <br/> <input type="file" name="filename[]" value="Upload2" /> <br/> <input type="submit" name="submitForm" value="Submit" /> </form> </body> </html> When i had this problem, I always thought maybe it was the type of data, like images, word docs, pdfs, specifically in FF. but it looks like i cant upload even text files with this simple script. Anyone got ideas? Quote Link to comment https://forums.phpfreaks.com/topic/52707-php-upload-doesnt-post-any-info-in-firefox/ Share on other sites More sharing options...
Barand Posted May 23, 2007 Share Posted May 23, 2007 The only thing in the $_POST array will be the submit button. The file data will be in the $_FILES array. Quote Link to comment https://forums.phpfreaks.com/topic/52707-php-upload-doesnt-post-any-info-in-firefox/#findComment-260241 Share on other sites More sharing options...
arianhojat Posted May 23, 2007 Author Share Posted May 23, 2007 Hey barand, when posting, $_POST still has 0 things in it. So it should at least have the submit button like you said, and MAX_FILE_SIZE hidden var. Quote Link to comment https://forums.phpfreaks.com/topic/52707-php-upload-doesnt-post-any-info-in-firefox/#findComment-260248 Share on other sites More sharing options...
Barand Posted May 23, 2007 Share Posted May 23, 2007 I trimmed the code down and works OK <?php if (isset($_POST['submitForm'])) { echo '<pre> POST ', print_r($_POST, true), '</pre>'; echo '<pre> FILES ', print_r($_FILES, true), '</pre>'; } ?> <form name="upload" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>"> File to upload: <br/> <input type="file" name="filename[]" value="Upload1" /> <br/> <input type="file" name="filename[]" value="Upload2" /> <br/> <input type="submit" name="submitForm" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/52707-php-upload-doesnt-post-any-info-in-firefox/#findComment-260260 Share on other sites More sharing options...
arianhojat Posted May 24, 2007 Author Share Posted May 24, 2007 hey barand, Still doesnt work for me. Maybe its an IIS/php issue. Quote Link to comment https://forums.phpfreaks.com/topic/52707-php-upload-doesnt-post-any-info-in-firefox/#findComment-260667 Share on other sites More sharing options...
craygo Posted May 24, 2007 Share Posted May 24, 2007 I use IIS and php and this works fine for me. Looks just like yours really, maybe it is that you are using "filename". But here is my working code. <?php $absolute_path = "C:/Inetpub/wwwroot/phpforum/images"; //Absolute path to where files are uploaded $size_limit = "yes"; //do you want a size limit yes or no. $limit_size = "600000"; //How big do you want size limit to be in bytes $limit_ext = "yes"; //do you want to limit the extensions of files uploaded $ext_count = "3"; //total number of extensions in array below $extensions = array(".jpg", ".png", ".gif"); //List extensions you want files uploaded to be if(!isset($_POST['submit'])){ $extens = ''; if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) { $extens = "any extension"; } else { $ext_count2 = $ext_count+1; for($counter=0; $counter<$ext_count; $counter++) { $extens .= " $extensions[$counter]"; } } if (($limit_size == "") or ($size_limit != "yes")) { $limit_size = "any size"; } else { $limit_size .= " bytes"; $mb_size = ($limit_size/1000000); } $pichead = "<li><font size=\"2\" color=660000>File extension must be $extens<b>"; $pichead .="</b></font> <li><font size=\"2\" color=660000>Maximum file size is $limit_size ($mb_size MB)</font></li> <li><font size=\"2\" color=660000>No spaces in the filename</font></li>"; ?> <html> <head> <title>HTML Form for uploading image to server</title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <html> <title>Add Vehicle Form</title> <body> <p><? echo $pichead; ?></p> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p>Pictures:<br /> 1 <input type="file" name="pictures[]" /><br /> 2 <input type="file" name="pictures[]" /><br /> 3 <input type="file" name="pictures[]" /><br /> 4 <input type="file" name="pictures[]" /><br /> 5 <input type="file" name="pictures[]" /><br /> 6 <input type="file" name="pictures[]" /><br /> <input type="submit" name=submit value="Send" /> </p> </form> <?php } else { $i=0; foreach ($_FILES["pictures"]["error"] as $key => $error) { $file_name = $_FILES["pictures"]['name'][$i]; // can call this anything you like this will take the original name $file = $_FILES["pictures"]['tmp_name'][$i]; $file_size = $_FILES["pictures"]['size'][$i]; $endresult = "<font size=\"4\" color=990000>$file_name uploaded successfully</font>"; if ($file_name == "") { $pic = $i+1; $endresult = "<font size=\"4\" color=990000>Pic#$pic Not selected</font>"; }else{ if(file_exists("$absolute_path/$file_name")) { $endresult = "<font size=\"4\" color=990000>File Already Existed</font>"; } else { if (($size_limit == "yes") && ($limit_size < $file_size)) { $endresult = "<font size=\"4\" color=990000>File was to big</font>"; } else { $ext = strrchr($file_name,'.'); if (($limit_ext == "yes") && (!in_array($ext,$extensions))) { $endresult = "<font size=\"4\" color=990000>File is wrong type</font>"; }else{ move_uploaded_file($file, "$absolute_path/$file_name"); } } } } $i++; echo $endresult."<br>"; } } ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/52707-php-upload-doesnt-post-any-info-in-firefox/#findComment-260688 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.