我一直在寻找解决方案,但我找不到答案.
我创建了一个图片上传表单.它使用ajaxform插件运行.但它仍然没有上传到目录.error_log说
move_uploaded_file()无法将文件从[tmp]移动到[dir].
然后在前端显示上传完成.但是当调用文件时,它不存在.
HTML代码:
JS:
var options = { beforeSend: function() { $(".imguploadProgress").show(); $(".imguploadProgressBar").width('0%'); $(".imguploadMsg").html(""); $(".imguploadProgressPercent").html("0%"); }, uploadProgress: function(event, position, total, percentComplete) { $(".imguploadProgressBar").width(percentComplete+'%'); $(".imguploadProgressPercent").html(percentComplete+'%'); }, success: function() { $(".imguploadProgressBar").width('100%'); $(".imguploadProgressPercent").html('100%'); }, complete: function(response) { alert('Complecion'); }, error: function() { $(".imguploadMsg").html(" ERROR: unable to upload files"); } }; $("#profpicform").ajaxForm(options);
SEVER SIDE:
$output_dir = home_url()."/path/to/dir/"; if(isset($_FILES["profpic"])){ if ($_FILES["profpic"]["error"] > 0){ echo "Error: " . $_FILES["file"]["error"] . "
"; }else{ move_uploaded_file($_FILES["profpic"]["tmp_name"],$output_dir. $_FILES["profpic"]["name"]); if(get_user_meta($_SESSION['userid'], 'user_profile_picture')==""){ add_user_meta($_SESSION['userid'], 'user_profile_picture', $_FILES['profpic']); }else{ update_user_meta($_SESSION['userid'], 'user_profile_picture', $_FILES['profpic']); } echo "Uploaded File :".$_FILES["profpic"]["name"]; } }
它们只能在一个PHP文件中找到.该目录的文件夹权限是777.
试试这个:
$destination_path = getcwd().DIRECTORY_SEPARATOR; $target_path = $destination_path . basename( $_FILES["profpic"]["name"]); @move_uploaded_file($_FILES['profpic']['tmp_name'], $target_path)