我有這樣的代碼,我一直在努力,但我有一個很難爲它工作。我做了一個,但它只適用於PHP 5.3,我意識到我的主機只支持PHP 5.0!我是想看看我是否能得到它在我的服務器正常工作,我只是失去了,累了笑有人可以幫我修復我的代碼嗎?
01,對不起計算器對我來說是一個新事物。不知道該怎麼想。作爲一個論壇或發佈問題的地方......嗯,我很抱歉對我提問的方式粗魯。
我不知道我能不能給我如何正確地插入目錄結構與我如何寫這個代碼的一些指導。我不知道如何告訴PHP在哪裏上傳我的文件和諸如此類的東西,我從一個朋友,誰幫我整理一下我的一些錯誤的一些幫助,但我仍然有對付的mkdir和鏈路丟失,斷開鏈接功能。這就是我想提到我的直覺嗎?
我知道php 5.3使用_ DIR _和php 5.0使用dirname(_ _ FILE_ _),我已經嘗試了兩個,我得到了同樣的錯誤。出於測試目的,我的文件被設置爲0777。它現在想要寫入和移動我上傳的文件有什麼問題?
} elseif ((file_exists("\\uploads\\{$username}\\images\\banner\\{$filename}")) || (file_exists("\\uploads\\{$username}\\images\\banner\\thumbs\\{$filename}"))) {
$errors['img_fileexists'] = true;
}
if (! empty($errors)) {
unlink($_FILES[IMG_FIELD_NAME]['tmp_name']); //cleanup: delete temp file
}
// Create thumbnail
if (empty($errors)) {
// Make directory if it doesn't exist
if (!is_dir("\\uploads\\{$username}\\images\\banner\\thumbs\\")) {
// Take directory and break it down into folders
$dir = "uploads\\{$username}\\images\\banner\\thumbs";
$folders = explode("\\", $dir);
// Create directory, adding folders as necessary as we go (ignore mkdir() errors, we'll check existance of full dir in a sec)
$dirTmp = '';
foreach ($folders as $fldr) {
if ($dirTmp != '') { $dirTmp .= "\\"; }
$dirTmp .= $fldr;
mkdir("\\".$dirTmp); //ignoring errors deliberately!
}
// Check again whether it exists
if (!is_dir("\\uploads\\$username\\images\\banner\\thumbs\\")) {
$errors['move_source'] = true;
unlink($_FILES[IMG_FIELD_NAME]['tmp_name']); //cleanup: delete temp file
}
}
if (empty($errors)) {
// Move uploaded file to final destination
if (! move_uploaded_file($_FILES[IMG_FIELD_NAME]['tmp_name'], "/uploads/$username/images/banner/$filename")) {
$errors['move_source'] = true;
unlink($_FILES[IMG_FIELD_NAME]['tmp_name']); //cleanup: delete temp file
} else {
// Create thumbnail in new dir
if (! make_thumb("/uploads/$username/images/banner/$filename", "/uploads/$username/images/banner/thumbs/$filename")) {
$errors['thumb'] = true;
unlink("/uploads/$username/images/banner/$filename"); //cleanup: delete source file
}
}
}
}
// Record in database
if (empty($errors)) {
// Find existing record and delete existing images
$sql = "SELECT `bannerORIGINAL`, `bannerTHUMB` FROM `agent_settings` WHERE (`agent_id`={$user_id}) LIMIT 1";
$result = mysql_query($sql);
if (!$result) {
unlink("/uploads/$username/images/banner/$filename"); //cleanup: delete source file
unlink("/uploads/$username/images/banner/thumbs/$filename"); //cleanup: delete thumbnail file
die("<div><b>Error: Problem occurred with Database Query!</b><br /><br /><b>File:</b> " . __FILE__ . "<br /><b>Line:</b> " . __LINE__ . "<br /><b>MySQL Error Num:</b> " . mysql_errno() . "<br /><b>MySQL Error:</b> " . mysql_error() . "</div>");
}
$numResults = mysql_num_rows($result);
if ($numResults == 1) {
$row = mysql_fetch_assoc($result);
// Delete old files
unlink("/uploads/$username/images/banner/" . $row['bannerORIGINAL']); //delete OLD source file
unlink("/uploads/$username/images/banner/thumbs/" . $row['bannerTHUMB']); //delete OLD thumbnail file
}
// Update/create record with new images
if ($numResults == 1) {
$sql = "INSERT INTO `agent_settings` (`agent_id`, `bannerORIGINAL`, `bannerTHUMB`) VALUES ({$user_id}, '/uploads/$username/images/banner/$filename', '/uploads/$username/images/banner/thumbs/$filename')";
} else {
$sql = "UPDATE `agent_settings` SET `bannerORIGINAL`='/uploads/$username/images/banner/$filename', `bannerTHUMB`='/uploads/$username/images/banner/thumbs/$filename' WHERE (`agent_id`={$user_id})";
}
$result = mysql_query($sql);
if (!$result) {
unlink("/uploads/$username/images/banner/$filename"); //cleanup: delete source file
unlink("/uploads/$username/images/banner/thumbs/$filename"); //cleanup: delete thumbnail file
die("<div><b>Error: Problem occurred with Database Query!</b><br /><br /><b>File:</b> " . __FILE__ . "<br /><b>Line:</b> " . __LINE__ . "<br /><b>MySQL Error Num:</b> " . mysql_errno() . "<br /><b>MySQL Error:</b> " . mysql_error() . "</div>");
}
}
// Print success message and how the thumbnail image created
if (empty($errors)) {
echo "<p>Thumbnail created Successfully!</p>\n";
echo "<img src=\"/uploads/$username/images/banner/thumbs/$filename\" alt=\"New image thumbnail\" />\n";
echo "<br />\n";
}
}
我收到以下錯誤:
警告:move_uploaded_file(./上傳/ saiyanz2k /圖片/橫幅/阿滋-wall.jpg)function.move上傳文件]:失敗打開流:權限在/services7/webpages/util/s/a/saiya.site.aplus.net/helixagent.com/public/upload2.php否認線112 警告:move_uploaded_file()以[function.move上傳-file]:無法在/services7/webpages/util/s/a/saiya.site移動 '/ /的Webdata/phpupload/phpVoIEQj服務' 到 './uploads/saiyanz2k/images/banner/azumanga-wall.jpg' .aplus.net/helixagent.com/public/upload2.php 112行
歡迎使用stackoverflow。您需要更新您的帖子,確認您收到的實際錯誤,或者解釋哪些功能無法正常工作。 您提供的代碼看起來應該可以在php 5.3和5.0中使用 – 2010-05-04 06:34:34
首先,您可以告訴我們它是如何失敗的。特別是說出你期望發生的事情和實際發生的事情,包括任何錯誤消息。這是相當多的代碼來通過。你應該嘗試創建一個最小的測試用例併發布,而不是把所有東西都扔在你的問題中。 – outis 2010-05-04 06:34:35
就我而言,我發現發佈300行代碼以及基本上說「它已損壞,請修復它」的單個段落有點不禮貌。 (比較:「不粗魯」將是12行代碼以及3段,解釋它做了什麼,它應該做什麼以及你準確收到什麼錯誤)。 – Tomalak 2010-05-04 06:55:27