【发布时间】:2015-11-24 21:11:48
【问题描述】:
我正在开发一个包含文件上传功能的网站。这在本地主机上运行良好,但是一旦我将站点上传到我的服务器,它就会失败。
我有以下代码来处理文件上传:
case "upload_to_gallery":
/*******************************
**** UPLOAD TO GALLERY ****
*******************************/
if ($con->checkLogin() && isset($_FILES['uploaded_files'])) {
$gallery_name = $_POST['gallery_name'];
for ($i = 0; $i < count($_FILES['uploaded_files']['name']); $i++) {
list($width, $height, $type, $attr) = getimagesize($_FILES["uploaded_files"]['tmp_name'][$i]);
if ($_FILES['uploaded_files']['type'][$i] == "image/png"
|| $_FILES['uploaded_files']['type'][$i] == "image/jpeg"
|| $_FILES['uploaded_files']['type'][$i] == "image/gif"
) {
$imgPath = "../files/img/galleries/" . $gallery_name . "/" . $_FILES['uploaded_files']['name'][$i];
$thumbPath = "../files/img/galleries/" . $gallery_name . "/thumbs/" . $_FILES['uploaded_files']['name'][$i];
move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$i], strtolower($imgPath));
$filehandler->makeThumbnails($imgPath, $thumbPath, 300, 215);
}
}
header('location: '.MAINPATH.'/galleri/'.$gallery_name.'?billeder_uploadet');
当我尝试在服务器上上传一些文件(图像)时,我遇到的错误是:
警告:move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]:无法打开流:/var/www/xn-中没有这样的文件或目录-cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 在第 35 行
警告:move_uploaded_file() [function.move-uploaded-file]:无法将 '/tmp/phptu17Hf' 移动到 /var/www/ 中的 '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 在第 35 行
警告:getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]:无法打开流:/var/www/xn--cstanlg-rxa 中没有这样的文件或目录.dk/public_html/lib/class/FileHandler.php 在第 158 行
警告:第 159 行 /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 中除以零
警告:第 159 行 /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 中除以零
警告:imagecreatetruecolor() [function.imagecreatetruecolor]:第 162 行 /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 中的图像尺寸无效
当我尝试将 0 个文件上传到服务器时,它给了我这个错误:
警告:getimagesize() [function.getimagesize]:第 26 行 /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 中的文件名不能为空
我认为这没有意义,因为我正在检查是否有任何文件已发送通过..
我认为这可能与服务器上的权限有关,但所有相关文件夹都设置为“755”。
我希望有人可能知道问题可能是什么。 任何帮助将不胜感激。
【问题讨论】:
-
如果你的路径有
test和Test(在前3个警告中)。选择一个并坚持下去。 Linux 对路径和文件夹/文件名区分大小写。 Windows 不是。 -
$_FILES['uploaded_files']存在并不意味着没有任何错误。检查错误。 -
感谢@D4V1D!就是这样。如果您发布答案,我会接受。还有@Charlotte Dunois,也谢谢。我将尝试检查错误。我刚刚读到它可以像我在我的问题中那样做,但显然情况并非如此:)
标签: php file-upload