Jump to content

File Upload ?


divadiva

Recommended Posts

Experts,

 

As my orignal code was not working on production.I have created a new one.

 

Again same thing it works fine in test/local machine.It fails in production.File permission is set to 777.All the paths are right.Any idea?

 

When I try to get phpconfiguration info "phpinfo" for upload_tmp_dir  for local and master it is blank for both local and test machine.

 

Here is the code:

 

 

<form action="./upload.php" method="post" enctype="multipart/form-data">
   <p>
      <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
      <button>Upload File</button>
   <p>
</form>




 

 


<?php
   // Configuration - Your Options
      $allowed_filetypes = array('.txt','.jpg','.gif','.bmp','.png','.pdf'); // These will be the types of file that will pass the validation.
      $max_filesize = 1771508; // Maximum filesize in BYTES (currently 0.5MB).
      //$upload_path = '../files/'; // The place the files will be uploaded to (currently a 'files' directory).
			$upload_path = '../files/'; // The place the files will be uploaded to (currently a 'files' directory). 
   echo $upload_path;
   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
  
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // I get this message.

?>

 

 

Best Regards,

Diva

Link to comment
https://forums.phpfreaks.com/topic/143478-file-upload/
Share on other sites

If the upload_tmp_dir is not set, php will use the the default temp folder of the operating system.

 

Are uploads enabled on the server? What does a phpinfo() statement show for the file_uploads setting?

 

Add the following to see what your script is receiving -

 

echo "<pre>";
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";

Link to comment
https://forums.phpfreaks.com/topic/143478-file-upload/#findComment-752628
Share on other sites

Adding your script gives me:

 

POST:Array ( ) FILES:Array ( [userfile] => Array ( [name] => test.txt [type] => [tmp_name] => [error] => 6 [size] => 0 ) )

 

PHP configuration has whole bunch of stuff.So ,I just took out the upload stuff

 

 

Directive                  Local Value	Master Value
upload_max_filesize	2M	2M
upload_tmp_dir	       no value	no value
user_dir	                    no value	no value


Link to comment
https://forums.phpfreaks.com/topic/143478-file-upload/#findComment-752646
Share on other sites

The upload error #6 does mean that there is no temp directory available, which would mean that your operating system also does not have a temp folder setting.

 

upload_tmp_dir is only settable in PHP_INI_SYSTEM, which means in php.ini or httpd.conf (I don't know if that includes a local php.ini). Do you have access to the master php.ini, httpd.conf, or a local php.ini? Those are your choices for doing this yourself or you will need to ask the host to set the value for you.

 

 

Link to comment
https://forums.phpfreaks.com/topic/143478-file-upload/#findComment-752668
Share on other sites

PFMaBiSmAd ,

 

Thankyou for replying.

 

I cannot access the php.ini.Is there any other means I could set it up via code?Should I recreate a directory and name it as temp?Any other suggestions ?

 

When I run the same in test I get this

POST:Array
(
)
FILES:Array
(
    [userfile] => Array
        (
            [name] => Q-000000226-001.pdf
            [type] => application/pdf
            [tmp_name] => /tmp/phpuzOIXA
            [error] => 0
            [size] => 46836
        )

)


 

 

Production gives me that:

 

 

POST:Array ( 
)
FILES:Array ( 
[userfile] => Array
(
[name] => test.txt
[type] => 
[tmp_name] => 
[error] => 6
[size] => 0 ) )


 

 

Best,

Diva

Link to comment
https://forums.phpfreaks.com/topic/143478-file-upload/#findComment-752674
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.