开发者

PHP copying or moving uploaded file - nothing happens, but no error

开发者 https://www.devze.com 2023-03-29 17:30 出处:网络
I\'m not getting any errors, but I\'m not getting the file copied either: $upload_folder = \"uploads/\";

I'm not getting any errors, but I'm not getting the file copied either:

$upload_folder = "uploads/";

$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);

$pref开发者_如何学编程ix = date("YmdHis");
$path_of_uploaded_file = "$upload_folder$prefix-$name_of_uploaded_file";
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];

if(is_uploaded_file($tmp_path))
{
  if(!copy($tmp_path,$path_of_uploaded_file))
  {
    $errors .= '\n error while copying the uploaded file';
  }
}

echo $path_of_uploaded_file;
echo $name_of_uploaded_file;
echo $errors;

This worked fine on a Windows development environment, but deploying to a Linux web server is doing this. We were getting a copying error initially, then we added permissions to the uploads directory. Now we get nothing.

I've also tried this with move_uploaded_file, no errors, but no resulting file in the uploads directory.


Maybe you can add a check if is_uploaded_file returns true.

if(is_uploaded_file($tmp_path))
{
  if(!copy($tmp_path,$path_of_uploaded_file))
  {
    $errors .= '\n error while copying the uploaded file';
  }
} else {
    $errors .= '\n error while uploading file'; // maybe  upload_max_filesize exceeded
// try to get the specific error

 switch($_FILES['uploaded_file']['error']){
    case 0: //no error; possible file attack!
      echo "There was a problem with your upload.";
      break;
    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
      echo "The file you are trying to upload is too big.";
      break;
    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
      echo "The file you are trying to upload is too big.";
      break;
    case 3: //uploaded file was only partially uploaded
      echo "The file you are trying upload was only partially uploaded.";
      break;
    case 4: //no file was uploaded
      echo "You must select an image for upload.";
      break;
    default: //a default error, just in case!  :)
      echo "There was a problem with your upload.";
      break;

}

maybe your upload_max_filesize exceeded, or there is another server setting that does not allow the upload.

see php dokumentation for more infos on possible problems.


$upload_folder = "uploads/";
$path_of_uploaded_file = "$upload_folder$prefix-$name_of_uploaded_file";

Make Your $path_of_uploaded_file to be

$path_of_uploaded_file = "$upload_folder/$prefix-$name_of_uploaded_file";
0

精彩评论

暂无评论...
验证码 换一张
取 消