简体   繁体   English

无法通过PHP将图像上传到FTP

[英]Cannot upload image to FTP via PHP

I am currently have some issues trying to get my php upload form to work. 我目前在尝试使我的php上传表单正常工作时遇到一些问题。 I am getting this error... Sorry, there was an error uploading your file. 我收到此错误...很抱歉,上传您的文件时出错。

The ftp connection if working fine i'm just unsure as to what could be stopping the upload. 的ftp连接,如果工作正常,我只是不确定什么会阻止上传。

This is the php... 这是PHP ...

$target_dir = "photos/";
$target_file = $target_dir . basename($_FILES["photo"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["photo"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
if ($_FILES["photo"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
} else {
    if (move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["photo"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
$res=mysql_query("INSERT INTO Photos (image_name, thumb, photo, photo_alt) VALUES 
('$_POST[image_name]', '$_POST[thumb]', '$_POST[photo]', '$_POST[photo_alt]')");

    if (array_key_exists ('check_submit', $_POST )) 

    if (!$res) {
        die('Invalid query: ' . mysql_error());
    }

    ?>

and the html.... 和html...。

    <input type ="hidden" value="1" name="check_submit" enctype="multipart/form-data"/>

     Please Enter Name: <input type ="text" name="image_name" /> <br />

     Tags: <input type ="text" name="photo_alt" /> <br />

     thumb  <input type="file" name="thumb" /><br/>

     image  <input type="file" name="photo" /><br/>

    <input type ="submit" name"Submit" /><br />

</form>

Thanks for reading. 谢谢阅读。

enctype属性应该在表单标签本身中

<form action="photos-upload.php" name="Myform" method="post" enctype="multipart/form-data">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM