简体   繁体   English

在cakephp中调试move_uploaded_file

[英]debugging move_uploaded_file in cakephp

I am using move_uploaded_file to upload files in cakephp, this was working for a while, but suddenly it broke. 我正在使用move_uploaded_file在cakephp中上载文件,这工作了一段时间,但突然坏了。 (I don't seem to see any recent changes in svn that relate to this issue, so I can't just revert them). (我似乎没有看到与该问题相关的svn最近的任何更改,因此我不能仅还原它们)。

The problem is, move_uploaded_file is returning false, but it isn't telling me what's wrong. 问题是,move_uploaded_file返回的是false,但没有告诉我出了什么问题。 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))
{
    // 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 托管服务器位于运行LAMP的ubuntu服务器9.10中,开发计算机是运行XAMPP的Windows 7

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: 在Cakephp配置中:

Configure::write('debug', 2);
Configure::write('log', E_ALL ^ E_NOTICE);

EDIT 2: 编辑2:

I did a scandir on $rel_url and it shows up the files just fine 我在$ rel_url上做了一个scandir,它显示了文件就好了

[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. 您说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. 我认为您进行了svn checkoutsvn update ,从而弄乱了您要上传到的目录的权限。 Check your permissions. 检查您的权限。

BTW: move_uploaded_file() is a native PHP function. 顺便说一句:move_uploaded_file()是本机PHP函数。 This has nothing to do with CakePHP. 这与CakePHP无关。

If file is been uploaded, and that the directory is 777, it might be that the paths are not correct. 如果文件已上传,并且目录为777,则可能是路径不正确。

Did you try to put a file in your target directory, and check with file_exists, if your $url is correct? 您是否尝试过将文件放在目标目录中,并通过file_exists检查,如果您的$ url正确?

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 ? 您是否检查目录所有者是否为www-data try : 尝试:

chown -R www-data:www-data /your/upload/folder/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM