我有这样的代码,我一直在努力,但我有一个很难为它工作。我做了一个,但它只适用于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