【发布时间】:2016-02-29 14:13:13
【问题描述】:
$targetFolder = '/LP/media/image'; // Relative to the root
if (!empty($_FILES)) {
$tmpName = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
//$ext = end(explode('.', $_FILES['Filedata']['name']));
$targetFile = rtrim($targetPath, '/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
echo $targetFile;
$fileParts = pathinfo($_FILES['Filedata']['name']);
$fileTypes = array('jpg', 'jpeg', 'png','JPG','JPEG','PNG'); // File extensions
if (in_array($fileParts['extension'], $fileTypes)) {
move_uploaded_file($tmpName, $targetFile);
//echo '1'.$fileParts['filename'];
// echo $fileParts['filename'];
$aimage = file_get_contents($tmpName);
// echo '<img src="data:image/jpeg;base64,' . base64_encode($aimage) . '" width=\'100\' height=\'100\' />';
} else {
echo 'Invalid file type.';
}
}
?>
相同的代码在我的本地机器上运行,但部署在远程服务器上。然后得到以下错误。
/home/username/public_html/LP/media/image/default_avatar.png
警告:move_uploaded_file(/home/username/public_html/LP/media/image/default_avatar.png) : 无法打开流:在 /home/username/public_html/uploadify/gallery.php 中没有这样的文件或目录 28警告:move_uploaded_file():无法将“/tmp/phpoe0fBd”移动到 /home 中的“/home/username/public_html/LP/media/image/default_avatar.png” /username/public_html/uploadify/gallery.php 第 28 行
【问题讨论】:
-
服务器上不存在您要移动的目录
-
检查权限。
-
可能什么都没有。这是我所说的关于名称属性和有效编码类型的 HTML 表单。我不知道 uploadify 足以进一步评论,但上传文件需要有效的 enctype 和 POST 方法。有人提到文件夹信箱。正如我在下面所说的,这仅适用于您在 UNIX/LINUX 上。在您打开 PHP 标记(例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);)之后将错误报告添加到文件顶部,然后是其余代码,以查看它是否产生任何结果。 -
还可以检查服务器上允许上传的最大大小
-
服务器上的 @jWeaver
$targetFolder = '/LP/media/image';意味着它将在文件系统的根目录中查找,因为斜线/它将无法找到目录。相反,您应该使用相对路径。