所以我的图片上传没有问题,但是在图片上传到表单提交后我得到的错误是什么?
这是我的一点点:
if(isset($_POST['submit'])){
if($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile)); //line 16
$fileUpload = move_uploaded_file($tmp_name,"blogUploads\images/".$image_name); //line 17
$image_name=time().".".$ext;
watermark_image($tmp_name,"blogUploads\images/".$image_name);
$img = ''.$image_name.'';
}else{
$img = '';
}
}
答案 0 :(得分:1)
表示错误:“文件名严格标准,只有变量应该通过引用传递”in end(explode())
1st将explode Array的结果分配给变量,然后将该变量传递给结束,如:
$tmp = explode('.', $namefile);
$file_extension = end($tmp);
或
$path_parts = pathinfo($filename);
$extension = $path_parts['extension'];
$fileName = $path_parts['filename'];
第二个用于move_uploaded_file()错误只是确保目标路径(第二个参数)有效(另外确保您的上传文件夹具有写入权限)
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
从http://w3schools.com/php/php_file_upload.asp
跟随“完整上传文件PHP脚本”PS:还应在move_uploaded_file()
之前分配$ image_name变量答案 1 :(得分:1)
通过以下方式更正第17行的目录结构:
$fileUpload = move_uploaded_file($tmp_name,"blogUploads\images\".$image_name);; //line 17
这里也是
watermark_image($tmp_name,"blogUploads\images\".$image_name);