Jump to content

Recommended Posts

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?

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>

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

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.