tags:

views:

119

answers:

2

I have a script on my server for uploading file. It is working fine before but suddenly it cannot upload files to the server. I did not change the code, I did not change anything related to php setting or directories permission also for the server. I did not change any thing in the webserver (apache). I created a small script to isolate the problem but I did not get any error messages or warning. The script are the following:


<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('error_reporting', E_ALL);

$target_path = "/var/www/vhosts/mydomain.com/httpdocs/userfiles3/2010-01-27/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
 } else{
   echo "There was an error uploading the file, please try again!";
}

?>
+1  A: 

According to your output:

var_dump($_FILES); 
array(1) { 
  ["uploadedfile"]=> array(5) { 
       ["name"]=> string(12) "DSC00562.JPG" 
       ["type"]=> string(0) "" 
       ["tmp_name"]=> string(0) "" 
       ["error"]=> int(2) 
       ["size"]=> int(0) 
  } 
}

The error 2 indicate that the field exceed the max filesize indicated into the html form as you can see http://www.php.net/manual/en/features.file-upload.errors.php

You should check if in the form you use to upload the file there is something similar to

<input type="hidden" name="MAX_FILE_SIZE" value="_a number_"/>

and remove it or specify a larger limit.

Eineki
Eineki. Thanks for help. This is the problem with the small script that I wrote for test.The original script get back to normal stat. now it can upload files without any problem! I did not change any thing
usef_ksa
A: 

I had a similar problem on one of the servers I was working on; the problem there was, that the temporary directory where php was storing the uploaded files had reached its allocated limit and therefore couldn't fit anything else in there.

After cleaning the directory of obsolete files it was working again.

Sorcy