Я пытаюсь загрузить файл через php-форму, но я получаю эту ошибку;Php Form Uploading File
[26-May-2016 17:07:55 America/Detroit] PHP Warning: move_uploaded_file(../uploads/2/slider2.jpg): failed to open stream: No such file or directory in /home/tefotv/public_html/6/php/fileupload.php on line 38
[26-May-2016 17:07:55 America/Detroit] PHP Warning: move_uploaded_file(): Unable to move '/tmp/php6SxeW0' to '../uploads/2/slider2.jpg' in /home/tefotv/public_html/6/php/fileupload.php on line 38
fileupload.php
<?php
include('../connect.php');
session_start();
header("refresh:1;url=../orders.php");
$orderid = $_SESSION['orderid'];
$sender = $_SESSION['id'];
if (!file_exists("../uploads/ $orderid ")) {
mkdir("../uploads/ $orderid ", 0700);
}
$target_dir = "/home/tefotv/public_html/6/uploads/$orderid/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "pdf") {
echo "Sorry, only JPG, JPEG, PNG & GIF & PDF 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["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
//Buradan itibaren
$filename = $_FILES["fileToUpload"]["name"];
$query = $db->prepare("INSERT INTO orderfile SET orderid = ?, userid = ?, patch = ? ");
$insert = $query->execute(array($orderid, $sender, $filename));
echo "UPDATED";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Как я могу это исправить?
Благодаря
Обновление- Обновление- Обновление- Обновление- Обновление- Обновление- Обновление- Обновление- Обновление-
Когда я изменил код так, он создает папку/дата загрузки/2, но загрузить файл/загрузить папку.
<?php
include('../connect.php');
session_start();
header("refresh:1;url=../orders.php");
$orderid = $_SESSION['orderid'];
$sender = $_SESSION['id'];
if (!file_exists("../uploads/$orderid ")) {
mkdir("../uploads/$orderid ", 0755);
}
$target_dir = "../uploads/$orderid";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
'если (! File_exists ("../ загрузки/$ OrderID")) {' удалить пробелы и в 'mkdir (« ../ uploads/$ orderid », 0700);' – RiggsFolly
@RiggsFolly не исправлено :(я получаю ту же ошибку – Can1
Попробуйте удалить следующее из $ target_dir/home/tefotv – Brett