使用php上传图片无法移动错误写入权限和用户权限是正确的

时间:2015-12-11 01:10:18

标签: 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_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]# 

upload_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
?>

表单profile.php

            <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>

js profile.php

  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);
        }
    });
}

0 个答案:

没有答案