上传后通过php上传图片大小

时间:2011-12-05 14:14:25

标签: php uploadify

我有以下脚本可以正常使用uploadify,我想做的是采取上传的图像,理想情况下使用imagejpeg(名称,空,质量)功能,以便我可以试验文件大小的变化。但是我无法让它发挥作用。我一直得到“imagejpeg():提供的参数不是一个有效的图像资源”错误。无论如何,这是我的代码 - 提前谢谢。

$tempFile = $_FILES['Filedata']['tmp_name'];

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';

//Make our unique file name token_time_orgfilename
$targetFile =  str_replace('//','/',$targetPath) . $token . "_" . time() . "_" . $_FILES['Filedata']['name'];

//name it without all the complete URL
$fileName =  $token . "_" . time() . "_" . $_FILES['Filedata']['name'];

if(!file_exists($targetPath)) { 
    mkdir($targetPath, 0755, true);
}   

move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$fileName);

1 个答案:

答案 0 :(得分:3)

imagejpeg用于输出(到浏览器或保存在磁盘上)图像,这是您在调整大小脚本末尾需要执行的操作。 您必须首先使用像http://php.net/imagecreatefromjpeg这样的函数创建gd资源,您必须为其提供上传文件的路径。 如果你这样做,你应该给我们调整大小脚本的代码。