Results 1 to 5 of 5

Thread: How to create an Upload-File Form in PHP?

  1. #1
    Join Date
    May 2009
    Posts
    258

    How to create an Upload-File Form in PHP?

    Hi friends,
    I have done some basic things in PHP programming language. Before PHP, I have done C# and Core Java. So I don't have enough information about the PHP. I want to upload file form but I don't know how to do that. So thought that someone over there would help me.. Please tell me how to create an Upload-File Form in PHP? Please reply me soon.!!

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: How to create an Upload-File Form in PHP?

    To allow users to upload files from a form can be very useful. Look at the following HTML form for uploading files :
    HTML Code:
    <html>
    <body>
    
    <form action="upload_demo.php" method="post"
    enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    
    </body>
    </html>

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to create an Upload-File Form in PHP?

    You will have to create the upload the script, before the HTML coding. The following example of coding explains the same :
    PHP Code:
    <?php
    if ($_FILES["file"]["error"] > 0)
      {
      echo 
    "Error: " $_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 
    "Stored in: " $_FILES["file"]["tmp_name"];
      }
    ?>

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to create an Upload-File Form in PHP?

    There are some restrictions on uploading the file :
    PHP Code:
    <?php
    if ((($_FILES["file"]["type"] == "pic/gif")
    || (
    $_FILES["file"]["type"] == "pic/jpeg")
    || (
    $_FILES["file"]["type"] == "pic/pjpeg"))
    && (
    $_FILES["file"]["size"] < 2000))
      {
      if (
    $_FILES["file"]["error"] > 0)
        {
        echo 
    "Error: " $_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 
    "Stored in: " $_FILES["file"]["tmp_name"];
        }
      }
    else
      {
      echo 
    "Invalid file";
      }
    ?>

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to create an Upload-File Form in PHP?

    The following coding would be useful for saving the uploaded file :
    PHP Code:
    <?php
    if ((($_FILES["file"]["type"] == "pic/gif")
    || (
    $_FILES["file"]["type"] == "pic/jpeg")
    || (
    $_FILES["file"]["type"] == "pic/pjpeg"))
    && (
    $_FILES["file"]["size"] < 2000))
      {
      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"];
          }
        }
      }
    else
      {
      echo 
    "Invalid file";
      }
    ?>

Similar Threads

  1. Procedure in VB to create form inside another form
    By Jalabala in forum Software Development
    Replies: 3
    Last Post: 16-11-2009, 02:14 PM
  2. Form to upload my file that renames
    By KALANI84 in forum Software Development
    Replies: 3
    Last Post: 15-10-2009, 10:47 PM
  3. How to create Form within Form in VB
    By StephanieRice in forum Software Development
    Replies: 2
    Last Post: 20-04-2009, 01:40 PM
  4. Create MDI form in VB.NET?
    By Swati in forum Software Development
    Replies: 4
    Last Post: 19-02-2009, 07:59 PM
  5. Need to create form in PHP!
    By Bhairav in forum Software Development
    Replies: 6
    Last Post: 25-09-2008, 01:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,773,056.83517 seconds with 17 queries