我有一个php uploadify脚本的问题。
我正在使用单个上传器,非多重。
这是我编辑的uploadify.php文件:
<?php
// Callin
require_once("../../includes/functions.php");
connect_db();
check();
// If file exists
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION); //figures out the extension
$newFileName = md5($tempFile).'.'.$ext; //generates random filename, then adds the file extension
$targetFile = str_replace('//','/',$targetPath) . $newFileName;
if($ext == "jpg" || $ext == "gif" || $ext == "png") {
$imgsize = getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3)))
{
case "jpg":
$image = imagecreatefromjpeg($targetFile);
break;
case "png":
$image = imagecreatefrompng($targetFile);
break;
case "gif":
$image = imagecreatefromgif($targetFile);
break;
default:
exit;
break;
}
$width = 180;
$height = 135; // Don't need proportional
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
if($bool)
{
switch(strtolower(substr($targetFile, -3)))
{
case "jpg":
header("Content-Type: image/jpeg");
$bool2 = imagejpeg($picture,$targetPath."../../galleries/vthumbs/".$_FILES['Filedata']['name'],80); // Two folders back to public_html, and /galleries/vthumbs/
break;
case "png":
header("Content-Type: image/png");
imagepng($picture,$targetPath."../../galleries/vthumbs/".$_FILES['Filedata']['name']); // Two folders back to public_html, and /galleries/vthumbs/
break;
case "gif":
header("Content-Type: image/gif");
imagegif($picture,$targetPath."../../galleries/vthumbs/".$_FILES['Filedata']['name']); // Two folders back to public_html, and /galleries/vthumbs/
break;
}
}
imagedestroy($picture);
imagedestroy($image);
}
else {
// If extension isn't jpg or gif or png just move file
move_uploaded_file($tempFile,$targetFile);
}
echo '0'; // Required to trigger onComplete function
}
else { // Required to trigger onComplete function
echo '1'; // For tests
// mysql_query .........
}
?>
我想要做什么? 我想制作上载视频和图像文件的上传器。 如果是图像,我想制作缩略图。我不关心完整的图像,如果不是图像文件,那一定是视频,只是上传视频。
我认为php代码工作正常,uploadify脚本没有来自uploadify.php的回调错误,但是当我将if (!empty($_FILES))
更改为if (empty($_FILES))
时,页面显示我0.通过这个,我thnik那个php代码没问题,没有错误。
但是文件没有上传。我检查了文件夹CHMOD和其他人。一切都好。 脚本适用于默认的uploadify.php代码。 我编辑的uploadify.php:
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
echo '0'; // Required to trigger onComplete function
}
else { // Required to trigger onComplete
echo '1';
}
?>
如果需要,我会在调用uploadify.php时粘贴javascript代码,但是我的Thnik没有任何意义,因为脚本适用于默认的uploadify.php和编辑的uploadify.php no。 欢迎所有帮助...
答案 0 :(得分:0)
将if (!empty($_FILES))
替换为if (sizeof($_FILES) > 0)