Php 移动上载的文件时出错

Php 移动上载的文件时出错,php,mysql,upload,Php,Mysql,Upload,我试着用下面的代码将一张图片上传到我服务器的一个目录中。但是,当我运行它时,会出现以下错误: 警告:move\u upload\u file(images/)[function.move upload file]:无法打开流:第24行的/home/a2943534/public\u html/add.php中是否有目录 警告:move_uploaded_file()[function.move uploaded file]:无法将第24行的“/tmp/php7yEkDe”移动到/home/a29

我试着用下面的代码将一张图片上传到我服务器的一个目录中。但是,当我运行它时,会出现以下错误:

警告:move\u upload\u file(images/)[function.move upload file]:无法打开流:第24行的/home/a2943534/public\u html/add.php中是否有目录

警告:move_uploaded_file()[function.move uploaded file]:无法将第24行的“/tmp/php7yEkDe”移动到/home/a2943534/public_html/add.php中的“images/”

请问,我这里缺什么

<?php
include_once("connect.php");
?> 
<?php 

 //This is the directory where images will be saved 
 $target = "images/"; 
 $target = $target . basename( $_FILES['photo']['title']); 

 //This gets all the other information from the form 
 $title=$_POST['title'];
 $name=$_POST['name']; 
 $describe=$_POST['describe']; 
 $pic=($_FILES['photo']['title']);
 $url=$_POST['url'];
 $country=$_POST['country'];
 $endDate=$_POST['endDate']; 


 //Writes the information to the database 
 mysql_query("INSERT INTO `authors` VALUES ('$title', '$name', '$describe', '$pic', '$url', '$country', '$endDate')") ; 

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

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

 //Gives and error if its not 
 $result =  "Sorry, there was a problem uploading your file."; 
 } 
 ?> 
<?php
// if the form has been submitted, display result
if (isset($result)) {
  echo "<p><strong>$result</strong></p>";
  }
?>


我认为你犯了一个错误

$target = $target . basename( $_FILES['photo']['title']); 
应该是哪一个

$target = $target . basename( $_FILES['photo']['name']); 
这是因为$\u文件['photo']中不存在标题

此错误还表示:

Unable to move '/tmp/php7yEkDe' to 'images/' in /home/a2943534/public_html/add.php on line 24

to images/不包含您的文件名。

此错误显而易见且不言自明。
第二个参数必须是文件名,而不是目录。

而不是写入

$target = $target . basename( $_FILES['photo']['title']);
你应该写

$target = $target . basename( $_FILES['photo']['name']); 

我认为除了SQL注入问题之外,没有什么比$_FILES['photo']['title']..

更像了。SQL注入问题似乎存在于每个PHP问题中,这些问题都以MySQL为特征,因此,您应该开始调试

在哪一行和哪一个函数调用导致了错误,这是一个非常明显的错误。在Google上查找错误,阅读您正在使用的函数的

长话短说:您应该创建两个变量,在调用函数之前打印它们,并找出错误所在

<?php

$source = $_FILES['photo']['tmp_name'];
$target = "images/" . basename( $_FILES['photo']['title']); 

echo "Moving '$source' to '$target'";

move_uploaded_file($source, $target);

确保
图像
目录确实存在。同时确保
图像
目录具有写入权限。首先,您缺少清理,导致任意文件写入漏洞。请看@JRSofty我很好奇,你有没有读过这个问题?你的PHP清楚地说你只提供了一个文件夹:“无法移动到‘images/’”,不是吗?请,我有上传功能,但我无法插入。请问有人知道为什么您没有了解“开始调试”部分的内容吗?:-)您的查询很可能会出错。打印它,分析它,改变它直到它工作。查看文档。