【发布时间】:2013-11-29 17:31:43
【问题描述】:
我创建了一个 PHP 和 MySQL 脚本,它通过 PHP 成功将提交的图像上传到我服务器上的文件夹,然后将带有扩展名的文件名添加到我的 MySQL 数据库中。
使用 FTP 程序,我可以在服务器上正确的文件夹中看到提交的图像,并且文件大小正确。但是,当我在浏览器中输入新上传图片的文件路径 (http://xxxxxx.com/images/image.jpg) 时,我得到一个空白页面。此外,当我尝试将图像导入网站时,什么也没有出现。
但是,当我通过 FTP 程序将图像重新下载到我的计算机上时,我可以看到图像完全正常。我错过了什么?
我的代码摘录如下:
<?php
// getting current post id and slug
$pid = $_POST['pid'];
$slug = $_POST['slug'];
//This is the directory where images will be saved
$target = '../company/'.$slug.'/images/';
$target = $target . basename( $_FILES['image']['name']);
//This gets all the other information from the form
$pic = ($_FILES['image']['name']);
$fileTmpLoc = ($_FILES["image"]["tmp_name"]);
$extract = explode(".", $pic);
$fileExt = end($extract);
list($width, $height) = getimagesize($fileTmpLoc);
if($width < 10 || $height < 10){
header("location: ../message.php?msg=ERROR: That image has no dimensions");
exit();
}
$rename = rand(100000000000,999999999999).".".$fileExt;
// check for correct filetype
if (!preg_match("/\.(gif|jpg|png)$/i", $pic) ) {
header("location: ../message.php?msg=ERROR: incorrect filetype");
exit();
}
include_once "../database-connect.php";
//Writes the information to the database
mysqli_query($dbconnection,"UPDATE companies SET picture='$rename' WHERE ID='$pid'") ;
//Writes the photo to the server
if(move_uploaded_file($fileTmpLoc, "../company/'.$slug.'/images/$rename"))
{
.... etc
我错过了什么,它没有显示在浏览器中?
【问题讨论】:
-
我唯一能想到的可能是您可能没有在 PHP 中加载
GD库。或者,也许,您使用 CMS,它有自己的 htaccess 重写规则,这些规则没有正确使用-f标志,因此不会忽略指令
标签: php mysql image upload ftp