我遇到了文件上传图片的问题。
当我尝试上传时,我收到此错误:
警告:copy(/ assets / img / products /):无法打开流:/ customers / d / 7/4 /(网站名称)/httpd.www/newSite/pages/admin中没有此类文件或目录第212行/adminPages/products.php
这是它所指的代码:
if(isset($_POST['submitMoreImg'])){
$name = $_POST['imgName'];
$prod_id = $_POST['prod_id'];
if(!empty($_FILES['image']))
{
$path = "/assets/img/products/";
$path = $path.basename( $_FILES['image']['imgName']);
if(copy($_FILES['image']['tmp_name'], $path)) {
echo'<script type="text/javascript">
alert("uploaded");
</script>';
uploadExtraImg($name, $prod_id);
}
else{
echo "Error: ".$sql."<br>".$connection->error;
}
}
}
我似乎无法找到正确的文件夹,我尝试了很多不同的文件夹路径。
答案 0 :(得分:0)
问题很明显。
Warning: copy(/assets/img/products/): failed to open stream: No such file or directory in /customers/d/7/4/(website name)/httpd.www/newSite/pages/admin/adminPages/products.php on line 212
它在目录/customers/d/7/4/(website name)/httpd.www/newSite/pages/admin/adminPages/products.php
但我希望你能得到/assets/img/products/customers/d/7/4
或作为完整路径(website name)/httpd.www/newSite/assets/img/products/customers/d/7/4
在那种情况下。请确保您的路径正确。
尝试更改$path
值。像这样
<?php
if(isset($_POST['submitMoreImg'])){
$name = $_POST['imgName'];
$prod_id = $_POST['prod_id'];
if(!empty($_FILES['image']))
{
$path = __DIR__."/../../../assets/img/products/";
$path = $path.basename( $_FILES['image']['imgName']) + $fileNameWithExtension;
if(copy($_FILES['image']['tmp_name'], $path)) {
echo'<script type="text/javascript">
alert("uploaded");
</script>';
uploadExtraImg($name, $prod_id);
}
else{
echo "Error: ".$sql."<br>".$connection->error;
}
}
}
?>