PHP文件上传,文件在move_uploaded_files之前从/ tmp中消失 [英] PHP File Upload, files disappearing from /tmp before move_uploaded_files

查看:147
本文介绍了PHP文件上传,文件在move_uploaded_files之前从/ tmp中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

move_uploaded_file()

code>失败,因为它无法在tmp文件夹中找到tmp文件。但我知道它被放在那里,但是在 move_upload_file()可以在我的脚本中处理它。我知道这是放在那里,因为我可以看到一个文件,当一个大文件被发布到服务器。



$ _ FILES 包含我刚刚上传的文件的正确详细信息。




$ b $有没有人知道为什么在我有机会处理临时文件之前,临时文件是从/ tmp中删除的?这是我正在使用的基本代码。

$ p $ if(move_uploaded_file($ _ FILES ['userfile'] [ 'tmp_name'],$ upload_file))
{
$ result ['error'] ='false';
$ result ['file_loc'] = $ upload_file;
}
else
{
$ result ['error'] ='true';

输出 print_r($ _ FILES) code>看起来像

  [userfile] =>数组

[name] => switchsolo.png
[type] => image / png
[tmp_name] => / tmp / phpIyKRl5
[错误] => 0
[size] => 6690



<

解决方案

1)post_max_size和upload_max_filesize是否保持比2)您的上传脚本执行的时间比max_execution_time变量允许的长吗?$ / b>

$ 3)我假设你的上传脚本不会像memory_limit变量允许的那样消耗尽可能多的内存。当客户端将文件上载到服务器时,服务器可能会在内存中保存一些文件。我不确定它是否会影响php.ini中memory_limit变量的限制。



这些变量可以在php.ini和/或.htaccess中更改,或者与ini_set()。



希望有帮助。


I have a very basic upload script, probably lifted straight off the php.net/move_upload_files function page.

move_uploaded_file() is failed because it cannot find the tmp file in the tmp folder. But I KNOW that it is being put there, but is removed before move_upload_file() can deal with it in my script. I know it is being put there since I can see a file in there when a large file is being posted to the server.

Also $_FILEScontains correct details for the file I have just uploaded.

Had anyone have any idea why the temporary file is being removed from /tmp before I have a chance to handle it?

Here is the basic code that I am using.

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_file))
{
    $result['error'] = 'false';
    $result['file_loc'] = $upload_file;
}
else
{
    $result['error'] = 'true';
}

The output of print_r($_FILES) looks like

[userfile] => Array
(
    [name] => switchsolo.png
    [type] => image/png
    [tmp_name] => /tmp/phpIyKRl5
    [error] => 0
    [size] => 6690
)

But /tmp/phpIyKRl5 simply isn't there.

解决方案

1) Are the post_max_size and upload_max_filesize holding higher value than the size of the file you are trying to upload?

2) Does your uploading script take longer time to execute than the value of the max_execution_time variable allows?

3) I assume your uploading script doesn't consume as much memory as the memory_limit variable allows. When the client is uploading the file to the server, then the server is probably holding some of it in memory while doing so. I'm not sure if it somehow affects the limit of the memory_limit variable in php.ini.

These variables can be changed in php.ini and/or .htaccess or with ini_set().

Hope that helps.

这篇关于PHP文件上传,文件在move_uploaded_files之前从/ tmp中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆