Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 上载带有php的图像无法移动错误写入权限和用户权限正确_Javascript_Php_Linux_Apache - Fatal编程技术网

Javascript 上载带有php的图像无法移动错误写入权限和用户权限正确

Javascript 上载带有php的图像无法移动错误写入权限和用户权限正确,javascript,php,linux,apache,Javascript,Php,Linux,Apache,您好,我有一个用ajax上传图像的小脚本,我的httpd错误日志我收到以下错误: [Fri Dec 11 01:04:23 2015] [error] [client 198.179.137.231] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpBvMSXh' to '/var/www/html/images/user_images/12241438_729936823776897_6949919207874282255

您好,我有一个用ajax上传图像的小脚本,我的httpd错误日志我收到以下错误:

[Fri Dec 11 01:04:23 2015] [error] [client 198.179.137.231] PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpBvMSXh' to '/var/www/html/images/user_images/12241438_729936823776897_6949919207874282255_n.jpg' in /var/www/html/upload_image.php on line 4, referer: http://52.35.215.63/profile.php
我已经将images/user_images权限设置为666和用户apache,因为用户httpd就是在这个权限下运行的

[root@ip-172-31-23-199 images]# ls -la
total 12
drw-rw-rw- 3 apache apache 4096 Dec 11 00:41 .
drwxr-xr-x 6 apache apache 4096 Dec 11 01:00 ..
drw-rw-rw- 2 apache apache 4096 Dec 11 00:41 user_images
[root@ip-172-31-23-199 images]# 
上传_image.php

<?php
$sourcePath = $_FILES['file']['tmp_name'];   // Storing source path of the file in a variable
$targetPath = "/var/www/html/images/user_images/".$_FILES['file']['name']; // Target path where file is to be stored
move_uploaded_file($sourcePath,$targetPath) ;    // Moving Uploaded file
?>

一个问题是,甚至在上载文件之前,脚本中就已经执行了
move\u uploaded\u file()
。。。。您需要测试表单是否已在代码中提交,并且仅在表单已提交时执行移动。这些是单独的脚本,我想我应该更具体一些。你没有看到我发布的错误代码吗?它显示了显示上载图像的确切错误,因为它是正确的图像名称@一个问题是,即使在上载文件之前,脚本中也执行了
move\u uploaded\u file()
。。。。您需要测试表单是否已在代码中提交,并且仅在表单已提交时执行移动。这些是单独的脚本,我想我应该更具体一些。你没有看到我发布的错误代码吗?它显示了显示上载图像的确切错误,因为它是正确的图像名称@马克贝克
            <form id="uploadimage" method="post" enctype="multipart/form-data">
                <div id="image_preview"><img id="previewing" src="" /></div>
                <div id="selectImage">
                <label>Select Your Image</label><br/>
                <input type="file" name="file" id="file" required />
                <input type='hidden' name='file_name' id='user_name'>
                <button onclick="uploadImage();">upload</button>
                <input type="submit" value="Upload" class="submit" />
                </div>
            </form>
  function uploadImage(){
    var user_name = document.getElementById("userid").value;
    document.getElementById("user_name").value = user_name;
    var form = document.getElementById('uploadimage');
    var formData = new FormData(form);
    $.ajax({
        url: "upload_image.php", // Url to which the request is send
        type: "POST",             // Type of request to be send, called as method
        data: formData, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
        contentType: false,       // The content type used when sending data to the server.
        cache: false,             // To unable request pages to be cached
        processData:false,        // To send DOMDocument or non processed data file it is set to false
        success: function(data)   // A function to be called if request succeeds
        {
            console.log(data);
        }
    });
}