php上传表格,Php表格上传文件

我尝试通过

PHP表单上传文件但我收到此错误;

[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

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.";

}

}

?>

我怎样才能解决这个问题?

谢谢

更新 – 更新 – 更新 – 更新 – 更新 – 更新 – 更新 – 更新 – 更新 –

当我更改这样的代码时,它会创建/ uploads / 2文件夹,但将文件上传到/ upload文件夹.

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值