簡體   English   中英

無法使用PHP上傳文件夾內的文件

[英]Can not Upload file inside folder using PHP

在將文件上傳到項目文件夾中時遇到問題。我在下面解釋我的代碼。

$imageName=generateRandomNumber().'_'.$_FILES["uploadme"]["name"];
$target_dir = "upload1/";
    $target_file = $target_dir . basename($imageName);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    $check = getimagesize($_FILES["uploadme"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
      if (file_exists($target_file)) {
      echo "Sorry, file already exists.";
      $uploadOk = 0;
    }
    // Check file size
   if ($_FILES["uploadme"]["size"] > 500000) {
      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["uploadme"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["uploadme"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
  }

在這里,我正在獲取圖像並為其添加一個隨機數,但是在上傳圖像時無法保存在upload1 Sorry, there was an error uploading your file 。在這里Sorry, there was an error uploading your file我得到的是Sorry, there was an error uploading your file消息時Sorry, there was an error uploading your file 。請幫助我解決此問題。

通過右鍵單擊文件夾並選擇權限選項卡來授予文件夾權限,然后通過允許在文件夾中創建和刪除文件來授予文件夾權限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM