我有一个php uploadify脚本的问题。问题处理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 .........
}
?>
我想要做什么呢? 我想制作上传器来上传视频和图片文件。 如果它是我想做的只是缩略图的图像。我不关心完整的图像,如果不是图像文件,那必须是视频,只是上传视频。
我thnik,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没有。 所有帮助是值得欢迎...
添加您的修改,一个接一个,直到它打破。然后你会知道哪些修改会破坏原始代码。到那时,它会很明显是什么错 - 这是基本的调试! - 或者你可以在这里发布一个真正具体的问题。 SO不喜欢“调试我的代码PLZ”。 – 2011-03-02 13:53:36
我已经开始进行经典的调试......当然不是,PHP担心。 我已经设置了这个纯巧合,我预测了一个灾难性的错误 – 2011-03-02 13:57:41
设置一个测试表单,它直接调用上传处理页面,因此您可以更容易地捕获输出和调试,而不会阻碍javascript层。 – horatio 2011-03-02 17:21:50