开发者

file upload from iPhone to PHP not worked

When uploading a file from iPhone, my code produces the following error:

Warning: move_uploaded_file() Unable to move '/tmp/phpUcqFVq' to '/var/www/ds1134/http.www.xxx.com/app/1316254141147.jpg' in /var/www/ds1134/https.www.xxx.com/user.php on line 2866

$_FILES looks like:

 [file] => Array
 (
    [name]     => 1316250632283.jpg
    [type]     => 
    [tmp_name] => /tmp/phpFio7gb
    [error]    => 0
    [size]     => 35515
 )

My PHP code for uploading is:

if (move_uploaded开发者_运维知识库_file($_FILES["file"]["tmp_name"], "/var/www/ds1134/http.www.xxx.com/app/".$_FILES["file"]["name"]))
{
    echo "done";
}


You could add some precondition checks to find out why the file could not be written:

$tmpName = $_FILES["file"]["tmp_name"];
$destDir = "/var/www/ds1134/http.www.xxx.com/app";
$destName = $destDir.$_FILES["file"]["name"];

if (!is_directory($destDir)
{
    throw new Exception('Destination is not a directory.');
}

if (!is_writable($destDir))
{
    throw new Exception('Destination directory is not writable.');
}

if (!preg_match('/^\d{13}\.jpg$/', $destName)
{
    throw new Exception('Invalid destination filename given. Only accepting 13 digits plus ".jpg".');
}

$destination = $destDir.'/'.$destName;

if (is_file($destination))
{
    throw new Exception('Destination filename already exists.');
}

if (virus_found($tmpName))
{
    throw new Exception('Upload file contains a virus.');
}

if (!imagecheck_validate_jpg($tmpName, 'color,24bit,size<1mb,in300x300,browser-compatible'))
{
    throw new Exception('Uploaded file does not meet the image requirements.');
}

if (move_uploaded_file($tmpName, $destination))
{
    echo "done";
}
else
{
    throw new Exception('Unable to move file.');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜