Problem with my file upload.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ddwornik
Forum Newbie
Posts: 1
Joined: Sat May 17, 2003 12:43 pm
Location: Delaware

Problem with my file upload.

Post by ddwornik »

I have written a script for work that accepts files and emails a notification.

This script works about 99% of the time, but the other 1% of the time I get notice undefined index uploaded_file every place I use the $_FILES array.

the full reference to the file is $_FILES['uploaded_file']['whatever'][$index]

where index is 0,1,or2 (we can receive 3 files)

in the html form I use name=uploaded_file[]

this problem has happened twice now that I know of.

once was when one of our employees tried to send a file to another store and once was with a customer.

It has happened on both a Windows box and on an OS9 box.

The OS9 box did it for about 15 minutes then started working again.

I use php 4.3.0

My question is, is this a problem in my php or in the web browser?

also is my use of file_name[] possibly problematic?

I am posting this here instead of figuring it out because I cannot force the problem to debug it on my own.


the form is at:
http://www.azteccopies.com
then click on submit jobs online (please do not send us lots of junk and in the email address form make it ignore@emailname@domain.com (this way it can be quickly weeded out of our work flow, but I can contact you))

You can also just use ignore@ignore or something if you do not want to be contacted.

here is the script I use (warning poor code my cause eyes to bleed).

The html stuff is to insert a table into a results page, but my only problem is with the places I use $_FILES[] the lines that loop come up 3 times (obviously).

The search and replace is because cooky mac designers were sending files like
*something_12/4/2002 rev4.3

and our unix server was not happy.

I think everything else has comments.

Code: Select all

//ob_end_flush(); /*uncomment for degugging*/ 
$file_nameї0] = ""; 
$file_nameї1] = ""; 
$file_nameї2] = ""; 

if ($_POSTї'recipient']=="censored@azteccopies.com") {$store="trolley"; 
        } elseif ( 
        $_POSTї'recipient']=="censored@azteccopies.com")   {$store="talley"; 
        } elseif ( 
        $_POSTї'recipient']=="censored@azteccopies.com")   {$store="pike"; 
        } else { 
        $_POSTї'recipient']="censored@azteccopies.com"; $store="";} 
/* the block above this verifies a valid destination email (unfortunatly hard coded, move to editable array in future) 
This way we cannot be abused as an anonymous relay */ 
$error_num_stat = 0; 
/*This line sets the error tracker to zero, it the error codes are set up as binary flags, but not yet used as such*/ 
/* the next three blocks of code are the file upload, they verify the field was filled (is_uploades_file) then move the file, if there is an error they flag either 001 010 100 bi 
nary (1 2 4).  the upload directory is a predefined prefix with the store name attached. */ 
$limit = array(0,1,2); 
//$index=0; 
foreach(array(0,1,2) as $index) { 
if ($_FILESї'uploaded_file']ї'name']ї$index] != "") { 
        $file_nameї$index] = $_FILESї'uploaded_file']ї'name']ї$index]; 
        $file_name&#1111;$index] = str_replace(array('*', '?', '!' ,'|' ,'\'' ,'/' ,'''', '"' ,'&#123;', '&#125;', '<' ,'>', ';', ',', '^', '(', ')', '$', '~'), 
                 '_', $file_name&#1111;$index]); 
        if (/* if upload fails (not succeeds)*/ 
        !move_uploaded_file($_FILES&#1111;'uploaded_file']&#1111;'tmp_name']&#1111;$index], 
        "/censored/file_name&#1111;$index])) 
                &#123;$error_num_stat = pow(2,$index);&#125;/*set the appropriate the flags are not used*/ 

        &#125; 
        &#125; 




/*if upload was good, send us an email*/ 
if ($error_num_stat==0)&#123; 
        mail($_POST&#1111;'recipient'], "Customer File Upload", $_POST&#1111;'Name']." sent the following file(s) 
\nfile 1:". $file_name&#1111;0]." 
\nfile 2:". $file_name&#1111;1]." 
\nfile 3:". $file_name&#1111;2]." 
\nThey should be available for you at the following website: 
\nhttp://www.azteccopies.com/censored/ 
\nplatform: ". $_POST&#1111;'Platform'] ." 
\nphone: ".$_POST&#1111;'Phone']." 
\nfax: ".$_POST&#1111;'fax']." 
\ndue: ".$_POST&#1111;'due_by']." 
\nemail: ".$_POST&#1111;'email']." 
\nInstructions: ".$_POST&#1111;'instructions'],"From: ".$_POST&#1111;'email']."\n"); 

//header ("location:thanks.html"); /*obsolete line if I fix this*/ 

$FILE1_string = $_FILES&#1111;'uploaded_file']&#1111;'name']&#1111;0]; 
$FILE2_string = $_FILES&#1111;'uploaded_file']&#1111;'name']&#1111;1]; 
$FILE3_string = $_FILES&#1111;'uploaded_file']&#1111;'name']&#1111;2]; 

//$FILES_size = array($_FILES&#1111;'uploaded_file']&#1111;'size']&#1111;0],$_FILES&#1111;'uploaded_file']&#1111;'size']&#1111;1],$_FILES&#1111;'uploaded_file']&#1111;'size']&#1111;2]); 


foreach(array(0,1,2) as $index) &#123; 
        $FILES_size&#1111;$index] = size_convert($_FILES&#1111;'uploaded_file']&#1111;'size']&#1111;$index]); 
        &#125; 
$files_string = "<br><br>We recived the following files from you:<br><br> 
<table cellpadding="2" cellspacing="2" border="0" color="#cc9900" 
style="text-align: center; width: 300px; font-size: 85%; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight: bold;"> 
  <tbody> 
    <tr> 
      <td style="text-align: center;">File Name<br> 
      </td> 
      <td>Size<br> 
      </td> 
    </tr> 
    <tr> 
      <td>".$_FILES&#1111;'uploaded_file']&#1111;'name']&#1111;0]."<br></td> 
      <td>".$FILES_size&#1111;0]."</td> 
    </tr> 
    <tr> 
      <td>".$_FILES&#1111;'uploaded_file']&#1111;'name']&#1111;1]."<br></td> 
      <td>".$FILES_size&#1111;1]."</td> 
    </tr> 
    <tr> 
      <td>".$_FILES&#1111;'uploaded_file']&#1111;'name']&#1111;2]."<br></td> 
      <td>".$FILES_size&#1111;2]."</td> 
    </tr> 
  </tbody> 
</table>"; 


//<br>$FILE1_string <br> $FILE2_string <br> $FILE3_string <br><br>"; 

// use color #C26100  for file names. 

$thanksstring = file_get_contents("./thanks.html"); 

$thanksstring = str_replace('<!--TEXTHERE-->',"$files_string",$thanksstring); 
print("$thanksstring");   /*otherwise print a bland error screen (should not happen ever)*/ 
&#125;else&#123; 

print("<h1>There was a problem when uploading your file(s)</h1> <p>Please retry the file upload</p> <p>If this is a repeat error then call the location closest to you</p> 
<p>error code:$error_num_stat"); 
&#125; 

function size_convert($file_size)&#123; 
if($file_size >= 1073741824) 
        &#123; 
        $file_size = round($file_size / 1073741824 * 100) / 100 . "GB"; 
        &#125; 
        elseif($file_size >= 1048576) 
        &#123; 
        $file_size = round($file_size / 1048575 * 100) / 100 . "MB"; 
        &#125; 
        elseif($file_size >= 1024) 
:      &#123; 
        $file_size = round($file_size / 1024 * 100) / 100 . "KB"; 
        &#125; 
        elseif($file_size > 0) 
        &#123; 
        $file_size = $file_size . "bytes"; 
        &#125; 
        else 
        &#123; 
        $file_size = ""; 
        &#125; 
return($file_size); 
&#125;
Post Reply