繁体   English   中英

php move_uploaded_file() 在生产中不起作用

[英]php move_uploaded_file() doesn't work in production

所以这是我的问题:我托管在 tsrato 上并想将文件上传到我的网络服务器,我懒得创建自己的,因为这个问题已经困扰我好几天了。 我认为网络服务器有一个 tmp 目录,但我无法将 tmp 目录重定向到我的上传文件夹。 那么如何将文件直接发送到 htdocs 和我的上传文件夹中。 下面的 php 代码位于另一个名为 inc 的目录中。 文件的大小和安全性无关紧要,我只想将一个文件移动到我的目录中。 这是我的网站空间的目录 /mnt/rid/XX/X2/51XX52582/htdocs/

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["userfile"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["userfile"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check if file already exists
if (file_exists($target_file)) {
  echo "Sorry, file already exists.";
  $uploadOk = 0;
}

// Check file size
if ($_FILES["userfile"]["size"] > 500000000) {
  echo "Sorry, your file is too large.";
  $uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
  echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["userfile"]["name"]). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}

检查您的/uploads文件夹是否可写。 如果它不可写并且您没有权限,则不会传输文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM