I am using move_uploaded_file to upload files in cakephp, this was working for a while, but suddenly it broke. (I don't seem to see any recent changes in svn that relate to this issue, so I can't just revert them).
The problem is, move_uploaded_file is returning false, but it isn't telling me what's wrong. I tried doing:
error_reporting(E_ALL);
ini_set("display_errors", 1);
but it isn't accomplishing anything. No errors are being reported.
if (!file_exists($folder_url . '/' . $filename))
{
/开发者_Go百科/ create full filename
$full_url = $folder_url . '/' . $filename;
$url = $rel_url . '/' . $filename;
// upload the file
error_reporting(E_ALL);
ini_set("display_errors", 1);
$success = move_uploaded_file($file['tmp_name'], $url);
$result['success'] = $success;
$result['debug']['url'] = $url;
$result['debug']['full_url'] = $full_url;
$result['debug']['file'] = $folder_url . '/' . $filename;
}
Hosting server is in ubuntu server 9.10 running LAMP, development machine is windows 7 running XAMPP
EDIT:
I changed the activate error reporting to before the upload and it still doesn't work:
error_reporting(E_ALL);
ini_set("display_errors", 1);
$success = move_uploaded_file($file['tmp_name'], $url);
In Cakephp Config:
Configure::write('debug', 2);
Configure::write('log', E_ALL ^ E_NOTICE);
EDIT 2:
I did a scandir on $rel_url and it shows up the files just fine
[test2] => Array
(
[0] => .
[1] => ..
[2] => 1.jpg
[3] => 10.jpg
[4] => 16.jpg
[5] => 2.jpg
[6] => 2010-12-12-0142065.jpg
[7] => 22.jpg
[8] => 3.jpg
[9] => 4.jpg
[10] => 5.jpg
[11] => 6.jpg
[12] => 7.jpg
[13] => 8.jpg
[14] => 9.jpg
[15] => error.png
)
[debug] => Array
(
[url] => img/recipes/555.jpg
[rel_url] => img/recipes
)
You say that there were updates in Subversion. I think that you did an svn checkout
or svn update
that messed up the permissions on the directory that you are trying to upload to. Check your permissions.
BTW: move_uploaded_file() is a native PHP function. This has nothing to do with CakePHP.
If file is been uploaded, and that the directory is 777, it might be that the paths are not correct.
Did you try to put a file in your target directory, and check with file_exists, if your $url is correct?
I had another problem once with the file filename. I don't remember exactly all the details, but it had to do with accented character in the filename.
EDIT
try with absolute url, that's what I do
$url = WWW_ROOT.'img/' . $filename;
Have you checked if the directory owner is www-data
? try :
chown -R www-data:www-data /your/upload/folder/
精彩评论