Moving an uploaded file using PHP

前端 未结 2 1515
时光取名叫无心
时光取名叫无心 2020-12-20 07:52

please could someone check this for me? I have followed the info that I found on here and still I cant get it to work. My host says that this should now be possible as the

相关标签:
2条回答
  • 2020-12-20 08:33
    <?php
    
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    
        if (file_exists("upload/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
          }
        }
    
    
    ?> 
    
    0 讨论(0)
  • 2020-12-20 08:51

    First of all please check that you are using a proper form tag

    <form action="upload_file.php" method="post" enctype="multipart/form-data">

    check that you have enctype="multipart/form-data" on form.

    in upload_file.php

    check that you are really getting the file by doing

    var_dump($_FILES)

    if yes, then you can use your move_uploaded_file

    0 讨论(0)
提交回复
热议问题