【问题标题】:xampp php file upload errorxampp php文件上传错误
【发布时间】:2014-06-09 02:00:47
【问题描述】:

我无法弄清楚我在 php 上上传的文件出了什么问题。

php代码:

<?php 
session_start();
if ($_SESSION['Loggedin']!="Yes") {
    header('location:index.php');
    exit();
}
require_once('Connect.php');

//This is the directory where images will be saved
$target = "../htdocs/sites/tryouts/newgames/images/main-news/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$author=$_POST['author'];
$title=$_POST['title'];
$pic=($_FILES['photo']['name']);
$bericht=$_POST['bericht'];



//Writes the information to the database
mysqli_query($Connection, "INSERT INTO nieuws (Nieuws_Author,Nieuws_Title,Nieuws_Image,Nieuws_Bericht)
VALUES ('$author', '$title', '$pic', '$bericht')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
  ?>

我收到 2 个错误:

警告: move_uploaded_file(../htdocs/sites/tryouts/newgames/images/main-news/bandicam 2014-05-2919-48-59-499.jpg):无法打开流:没有这样的文件或 目录在 C:\Users\xammp\htdocs\sites\tryouts\newgames\addnewsscripts.php 上 第 26 行

警告:move_uploaded_file():无法移动 'C:\Users\xammp\tmp\php24D.tmp' 到 '../htdocs/sites/tryouts/newgames/images/main-news/bandicam 2014-05-29 19-48-59-499.jpg' 在 C:\Users\xammp\htdocs\sites\tryouts\newgames\addnewsscripts.php 上 第 26 行 抱歉,上传您的文件时出现问题。

我已经检查了 php 文件上传是否已设置并且目录是:

upload_tmp_dir = "C:\Users\xammp\tmp"

你能弄清楚我做错了什么吗? 可能是我想放置图像的目录,但我需要使用哪个目标目录?

【问题讨论】:

  • 您将 Windows 路径与 Unix 路径混合在一起。这是不是 Windows 环境?
  • 是 windows 7 64 位

标签: php mysql file-upload xampp


【解决方案1】:

如果我们有

//This is the directory where images will be saved
$target = "../htdocs/sites/tryouts/newgames/images/main-news/";

还有错误

警告:move_uploaded_file():无法移动 'C:\Users\xammp\tmp\php24D.tmp''../htdocs/sites/tryouts/newgames/images/main-news/bandicam 2014-05-29 19-48-59-499.jpg' 在 C:\Users\xammp\htdocs\sites\tryouts\newgames\addnewsscripts.php 上 第 26 行 抱歉,上传您的文件时出现问题。

我会说您需要将路径更改为类似

$target = "C:\Users\xammp\htdocs\sites\tryout\newgames\images\main-news\";

【讨论】:

    猜你喜欢
    • 2012-06-18
    • 2010-09-05
    • 2012-05-04
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多