PHP image upload function, save in a dir and then return save image url

前端 未结 5 414
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 12:55

I am trying to upload an image to server using PHP and the save inside a dir, and then returning the image url.

HTML:



        
5条回答
  •  执念已碎
    2021-01-03 13:43

    First you need a multipart/form-data form for uploading. This is a must :)


    The PHP part is fairly simple: This would result your file stored in "upload/{filename}" The main part you want to consider is how to get the filename and back to your write_string_to_database procedure, you could do a simple script after the upload page like

    save_string_to_database("upload/" . $_FILES["file"]["name"]);
    

    would do the trick.

     0)
      {
      echo "Error: " . $_FILES["file"]["error"] . "
    "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); } }

提交回复
热议问题