2011-03-02 70 views
2

我有一個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沒有。 所有幫助是值得歡迎...

+0

添加您的修改,一個接一個,直到它打破。然後你會知道哪些修改會破壞原始代碼。到那時,它會很明顯是什麼錯 - 這是基本的調試! - 或者你可以在這裏發佈一個真正具體的問題。 SO不喜歡「調試我的代碼PLZ」。 – 2011-03-02 13:53:36

+0

我已經開始進行經典的調試......當然不是,PHP擔心。 我已經設置了這個純巧合,我預測了一個災難性的錯誤 – 2011-03-02 13:57:41

+0

設置一個測試表單,它直接調用上傳處理頁面,因此您可以更容易地捕獲輸出和調試,而不會阻礙javascript層。 – horatio 2011-03-02 17:21:50

回答

0

更換if (!empty($_FILES))if (sizeof($_FILES) > 0)