我正在使用PHP网站销售汽车。当用户想要出售他的汽车时,他需要添加图像。当我尝试这样做时,会发生以下错误: 警告:move_uploaded_file(C:/xampp/htdocs/carMela/mainSite/assets/image/4-BMW-E90AC-Kit-by-Xclusive-Customz-Sheffield_16959173929_l.jpg):无法打开流:C中没有此类文件或目录:第165行的\ 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 -Xclusive-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.');
}
}
答案 0 :(得分:0)
我走错路了
$this->uploadFilePath = $_SERVER["DOCUMENT_ROOT"].'/cars/';
就这样,所以我更改了它并成功了,谢谢您的帮助
答案 1 :(得分:-1)
我认为问题出在您的正斜杠和反斜杠,Windows使用反斜杠,而您使用的是Linux中使用的正斜杠,请尝试将其改为“ \”而不是“ /”。否则,如果那不是答案,那么您将不得不编辑您的问题并向我们显示您的目录结构,问题可能很简单,如拼写错误