Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php将图像上载到文件_Php_File Upload - Fatal编程技术网

使用php将图像上载到文件

使用php将图像上载到文件,php,file-upload,Php,File Upload,我想上传一个图像到一个文件使用php。我一直在简化代码,但仍然不起作用。一旦我发现了问题所在,我会重新添加参数。这是我的文件upload.php <html> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="upload" id="u

我想上传一个图像到一个文件使用php。我一直在简化代码,但仍然不起作用。一旦我发现了问题所在,我会重新添加参数。这是我的文件upload.php

<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="upload" id="upload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

<?php
if(isset($_POST["submit"])) {
$pathway= "uploads/";
$target_file = $pathway . basename($_FILES["upload"]["name"]);
    if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["upload"]["name"]). " has been uploaded.";
    }
}
?>

选择要上载的图像:

我已经创建了“uploads”文件夹,但没有向其中添加图像

首先,您必须确保php.ini中的属性文件_uploads=on 文件

其次,确保将upload_max_filesize设置为所需的大小

然后看看这个代码

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["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["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
    echo "File is not an image.";
    $uploadOk = 0;
    }
    }
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
 }
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
 } else {
      if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
      echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
     echo "Sorry, there was an error uploading your file.";
     }
}
?>


上传文件夹的权限是什么?权限?我使用Godaddy作为主机,uploads和upload.php都在同一个目录下。那么,那^?和权限,这意味着文件夹可写吗?你需要ping我们中的一个。我不能一直盯着这个问题等更新。设身处地为我们着想,你就会明白我的意思。我们发表评论以获得澄清并试图提供帮助,但我们坐在这里。。。。。等待。对你来说,这可能听起来像是不耐烦,但再一次;把你自己放在我们的位置上。我留下了一个问题,祝你好运。我真的希望你能找到问题所在。