PHP Uploading file unsuccessful

前端 未结 3 448
旧时难觅i
旧时难觅i 2021-01-27 05:43

I\'m trying to upload a file to my local server, but it keeps being unsuccessful.

All my files are inside /var/www/html/ However I made a folder called uploads in the h

3条回答
  •  佛祖请我去吃肉
    2021-01-27 06:22

    Try This:

    index.html

     
     
     
     
    Choose a file to upload:

    upload.php

    if(isset($_FILES["uploadedfile"]["type"]) && ($_FILES["uploadedfile"]["size"] < 5000000)){
          $sourcePath = $_FILES['uploadedfile']['tmp_name'];
          $file = $_FILES['uploadedfile']['name'];
          $targetPath = "/uploads/".$file;
          if(move_uploaded_file($sourcePath,$targetPath)){
          echo "The file: ".$_FILES['uploadedfile']['name']." has been uploaded";
       }else{
          echo "Looks like it failed.";
       }
    }else{
       echo "You forgot to select a file, or the file size is too large.";
    }
    

    So what this does is checks if a file exists and checks if it's smaller than 5MB. If so it moves on to the upload part.

提交回复
热议问题