PHP - 检查目标是否可写

时间:2016-04-20 15:43:57

标签: php

我正在尝试使用php将图像上传到服务器上的文件夹,但是我收到此错误消息:

Warning: move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpPoVMRg' to 'userImages/Test/Test 2.jpg' in /Applications/XAMPP/xamppfiles/htdocs/TestSite/upload.php on line 16
Error uploading file - check destination is writeable.

似乎有些东西阻止了上传。我的猜测是操作系统,但我不确定如何允许可写性。

我使用带有os x yosemite的mac。

以下是上传代码:

    <?php

session_start();

// Check for errors
if($_FILES['file_upload']['error'] > 0){
    die('An error ocurred when uploading.');
}

if(!getimagesize($_FILES['file_upload']['tmp_name'])){
    die('Please ensure you are uploading an image.');
}


// Upload file
if(!move_uploaded_file($_FILES['file_upload']['tmp_name'], 'userImages/Test/' . $_FILES['file_upload']['name'])){
    die('Error uploading file - check destination is writeable.');
}

die('File uploaded successfully.');


?> 

感谢您的回答!

1 个答案:

答案 0 :(得分:-1)

使用is_writable函数

users#update