Page 1 of 1

need help in uploading array of files

Posted: Mon Sep 29, 2003 2:26 am
by itsmani1
hi there.....
I need help in uploading an array of files
there is some problem in the code that i am using can any one help me to over come the problem

regards
Abdul Mannan

Code: Select all

if ($HTTP_POST_VARS['submit'])  
{ 
    if (!is_uploaded_file($HTTP_POST_FILES['file'][temp]))  
    { 
    $error = "You did not upload a file!"; 
    unlink($HTTP_POST_FILES['file'][temp]); 
    // assign error message, remove uploaded file, redisplay form. 
    } 
    else  
    { 
    //A file was uploaded 
    $maxfilesize=30000; 
        if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) 
        { 
            $error = "File is too large."; 
            unlink($HTTP_POST_FILES['file'][temp]); 
            // assign error message, remove uploaded file, redisplay form. 
        } 
        else  
        { 
       //File has passed all validation, copy it to the final destination and remove the temporary file: 
   copy($HTTP_POST_FILES['file'][temp],$HTTP_POST_FILES['file'][use]); 
   move_uploaded_file(['file'][use], "/place/file.new"); 

{ 
             unlink($HTTP_POST_FILES['file']);  
  
         print "File has been successfully uploaded!"; 
             exit();     
            }  
      } 
}
[mod_edit:

Code: Select all

tags added][/size]

Posted: Mon Sep 29, 2003 2:54 am
by volka
several issues
  • http://www.php.net/manual/en/features.file-upload.php wrote:Note: In PHP versions prior 4.1.0 this was named $HTTP_POST_FILES and it's not an autoglobal variable like $_FILES is. PHP 3 does not support $HTTP_POST_FILES.
    so, if you're doing this within a function you have to import $HTTP_POST_FILES before using it
  • $HTTP_POST_FILES['file'][temp]
    there's no element temp but tmp_name. Please also read http://www.php.net/manual/en/language.t ... rray.donts then use

    Code: Select all

    $HTTP_POST_FILES['file']['tmp_name']
  • unlink($HTTP_POST_FILES['file']);
    won't work,

    Code: Select all

    unlink($HTTP_POST_FILES['file']['tmp_name']);
    might but there's no need to remove the temporary file on the server, php will take care of it by itself
  • your code-snippet reformatted looks like

    Code: Select all

    if ($HTTP_POST_VARS['submit']) 
    {
    	if (!is_uploaded_file($HTTP_POST_FILES['file'][temp])) 
    	{
    		$error = "You did not upload a file!";
    		unlink($HTTP_POST_FILES['file'][temp]); // <- please read 
    		// assign error message, remove uploaded file, redisplay form.
    	}
    	else 
    	{
    		//A file was uploaded
    		$maxfilesize=30000;
    		if ($HTTP_POST_FILES['file']['size'] > $maxfilesize)
    		{
    			$error = "File is too large.";
    			unlink($HTTP_POST_FILES['file'][temp]);
    			// assign error message, remove uploaded file, redisplay form.
    		}
    		else 
    		{
    			//File has passed all validation, copy it to the final destination and remove the temporary file:
    			copy($HTTP_POST_FILES['file'][temp],$HTTP_POST_FILES['file'][use]);
    			move_uploaded_file(['file'][use], "/place/file.new");
    
    			{
    				unlink($HTTP_POST_FILES['file']); 
    				print "File has been successfully uploaded!";
    				exit();     
    			} 
    		}
    	}
    as you can see there's a mismatch of { and }s. Might be you only forgot to paste it here but you'd check that
  • copy($HTTP_POST_FILES['file'][temp],$HTTP_POST_FILES['file'][use]);
    move_uploaded_file(['file'][use], "/place/file.new");
    please explain that...

reply explanation

Posted: Mon Sep 29, 2003 3:20 am
by itsmani1

Code: Select all

copy($HTTP_POST_FILES&#1111;'file']&#1111;'temp'],$HTTP_POST_FILES&#1111;'file']&#1111;'use']); 
move_uploaded_file(&#1111;'file']&#1111;'use'], "/place/file.new");
Listen :o

First of all ['file']['temp'] will copy the ['file']['use']
and then it will upload or move the file ['file']['use'] to the "place/file.new"

['file'] = file name
['use'] = temp space
place/file.new = where to save on the server
that's it

Posted: Mon Sep 29, 2003 3:47 am
by pootergeist
so you copy the file at pointer $HTTP_POST_FILES['file']['temp'] to the location defined by pointer $HTTP_POST_FILES['file']['use'] (neither of which exist in the standard upload processing done by php) - thus overwriting whatever is there.
then you move the file again (or try to as ['file']['use'] is not a valid pointer without a global array definition) to /place/file.new from root.

maybe you should show us the code that creates the user variables ['temp'] and ['use'] in the http_post_files array - then we would at least maybe understand what they are trying to accomplish.

I'd suggest it better to just
unlink($HTTP_POST_FILES['file']['use']);
rather than overwrite it - then just move whatever is referenced by ['file']['use'] (with no array definition - must be some serious code to get that to do anything, maybe a pre-parser variable templating engine I guess) to the near root folder you defined.