<?
if(isset($_POST['submit'])){
$url = 'http://www.connectedcampus.org/ckeditor/images/uploads/';
if (($_FILES['upload'] == "none") OR (empty($_FILES['upload']['name'])) )
{
$message = "No file uploaded.";
}
else if ($_FILES['upload']["size"] == 0)
{
$message = "The file is of zero length.";
}
else if (($_FILES['upload']["type"] != "image/pjpeg") AND ($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/png"))
{
$message = "The image must be in either JPG or PNG format. Please upload a JPG or PNG instead.";
}
else if($_FILES["file"]["size"] > 1000000){
$message = "File size too big!";
}
else if(file_exists($url.$_FILES["file"]["name"]))
{
$message=$_FILES["file"]["name"] . " already exists. ";
}
else if (!is_uploaded_file($_FILES['upload']["tmp_name"]))
{
$message = "Invalid File!";
}
else {
$message = "success!";
$move = move_uploaded_file($_FILES['upload']['tmp_name'], $url.$_FILES['upload']['name']);
echo $_FILES['upload']['tmp_name']."<br>";
echo $url.$_FILES['upload']['name'];
if(!$move)
{
$message = "Error moving uploaded file.";
}
$url = $url.$_FILES['upload']['name'];
}
echo $message;
</script>";
}
?>
打印“移动上传文件时出错” 这意味着move_uploaded_file($ _ FILES ['upload'] ['tmp_name'],$ url。$ _ FILES ['upload'] ['name']) 返回false。但我500%确定我已正确创建http://www.connectedcampus.org/ckeditor/images/uploads/文件夹....那么为什么会出错?
好的,现在改为:
$url = 'bloguploads/';
if (($_FILES['upload'] == "none") OR (empty($_FILES['upload']['name'])) )
{
$message = "No file uploaded.";
}
else if ($_FILES['upload']["size"] == 0)
{
$message = "The file is of zero length.";
}
else if (($_FILES['upload']["type"] != "image/pjpeg") AND ($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/png"))
{
$message = "The image must be in either JPG or PNG format. Please upload a JPG or PNG instead.";
}
else if($_FILES["file"]["size"] > 1000000){
$message = "File size too big!";
}
else if(file_exists($url.$_FILES["file"]["name"]))
{
$message=$_FILES["file"]["name"] . " already exists. ";
}
else if (!is_uploaded_file($_FILES['upload']["tmp_name"]))
{
$message = "Invalid File!";
}
else {
$message = "";
$move = move_uploaded_file($_FILES['upload']['tmp_name'], $url.$_FILES['upload']['name']);
if(!$move)
{
$message = "Error moving uploaded file.";
}
$url = $url.$_FILES['upload']['name'];
}
echo $message;
</script>";
?>
现在的事情是,它说“已经存在”。为什么?我可以通过ftp客户端看到该文件尚未上传
答案 0 :(得分:1)
move_uploaded_file
适用于文件系统,而不适用于网址。
而不是
中的$url
move_uploaded_file($_FILES['upload']['tmp_name'], $url.$_FILES['upload']['name']);
使用文件系统路径,即:
move_uploaded_file($_FILES['upload']['tmp_name'], "/home/www/uploads/".$_FILES['upload']['name']);