PHP错误,表示我无法上载图像移动\u上载\u文件
我在一个销售汽车的PHP网站上工作。当用户想要出售他的汽车时,他需要添加一个图像。当我尝试这样做时,会出现以下错误: 警告:move_Upload_文件(C:/xampp/htdocs/carMela/mainSite/assets/image/4-BMW-E90AC-Kit-by-exclusive-Customz-Sheffield_16959173929_l.jpg):无法打开流:在第165行的C:\xampp\htdocs\cars\class\userPost\userPost.php中没有这样的文件或目录 警告:move_uploaded_file():无法将C:\xampp\tmp\phpCEDC.tmp移动到C:/xampp/htdocs/carMela/mainSite/assets/image/4-BMW-E90AC-Kit-by-exclusive-Customz-Sheffield_16959173929_l.jpg,位于C:\xampp\htdocs\cars\class\userPost\userPost.php的第165行 很抱歉,上载您的文件时出现问题 这条线是:PHP错误,表示我无法上载图像移动\u上载\u文件,php,Php,我在一个销售汽车的PHP网站上工作。当用户想要出售他的汽车时,他需要添加一个图像。当我尝试这样做时,会出现以下错误: 警告:move_Upload_文件(C:/xampp/htdocs/carMela/mainSite/assets/image/4-BMW-E90AC-Kit-by-exclusive-Customz-Sheffield_16959173929_l.jpg):无法打开流:在第165行的C:\xampp\htdocs\cars\class\userPost\userPost.php
if(move_uploaded_file($_FILES['car_image']['tmp_name'], $target))
这是我上传图像的代码:
/*this function for image uploaded */
public function save_image_info(){
$image_extensions_allowed = array("gif", "jpeg", "jpg", "png");
$file_name = $_FILES["car_image"]["name"];
$ext = strtolower(substr(strrchr($file_name, "."), 1));
$directory = $this->uploadFilePath.'mainSite/assets/image/';
$target = $directory . basename( $file_name) ;
$image_name = basename($file_name);
$new_img_url = $image_name;
$image_size = $_FILES['car_image']['size'];
if (!empty($_FILES)) {
if ($image_size > 5000000) {
die('File size is too large! Please upload Small file.');
} elseif(!in_array($ext, $image_extensions_allowed)) {
die("You must upload a file with one of the following extensions: ".$ext);
}
else{
//Now upload here
if(move_uploaded_file($_FILES['car_image']['tmp_name'], $target))
{
return $new_img_url;
}
else {
die('Sorry, there was a problem uploading your file.');
}
}
} else {
die('The file you Upload is not an image! Please upload a Valid Image.');
}
}
我认为问题在于你的前斜杠和反斜杠,windows使用的是反斜杠,而你使用的是linux中使用的前斜杠,试着将它们改为“\”而不是“/”。否则,如果这不是答案,您将不得不编辑您的问题并向我们显示您的目录结构,问题可能很简单,就像拼写错误一样我的路径不对
$this->uploadFilePath = $_SERVER["DOCUMENT_ROOT"].'/cars/';
就是这样,我改变了它,它工作了,谢谢你的帮助,然后第二个错误发生了:解析错误:语法错误,在C:\xampp\htdocs\cars\class\userPost\userPost.php的第155行出现了意外的“car_图像”(T_字符串),这是什么意思?这也是代码:$image\u size=$\u文件['car\u image']['size'];当我上传的时候,上面写着(C:/xampp/htdocs/carMela/mainSite/assets/image/,我的文件夹不是carMela它的测试,这是一个问题吗?我如何解决这个问题,这是一个github代码它可能是一个文件路径问题注意:mysqli的面向对象接口
mysqli
明显不那么冗长,使代码更易于阅读和审核,并且不容易与obs混淆oletemysql\u query
接口。在您对过程式风格投入太多之前,值得切换。例如:$db=new mysqli(…)
和$db->prepare(…)
过程接口是PHP 4时代的产物,当时引入了mysqli
API,不应在新代码中使用。警告:使用mysqli
时,应使用和将用户数据添加到查询中。不要使用字符串插值或连接来完成此操作,因为您创建了严重的.N如果将$\u POST
、$\u GET
或任何用户数据直接放入查询中,如果有人试图利用您的错误进行攻击,可能会非常有害。