How can i upload a picture?

Discussion in 'PHP' started by anisbd, Mar 5, 2008.

  1. #1
    hey all,
    How can i upload a picture use PHP?

    please help me
     
    anisbd, Mar 5, 2008 IP
  2. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #2
    smatts9, Mar 5, 2008 IP
  3. andy@pmr

    andy@pmr Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello,

    You need an html form e.g

     <form action="upload.php" method="POST" enctype="multipart/form-data">
      <input type="file" size="40" name="image_file" maxlength="50">
      <input type="Submit" value="Upload">
     </form>
    HTML:
    and a php file upload.php (this is a dumb insecure sample, you will have to add more code to make it safe)

    <?php
    
    // Where to upload the file
    $foldername = '/uploads/';
    
    // Copy the file to a fixed location
    copy ($_FILES['image_file']['name'], $foldername . $_FILES['image_file']['name']); 
    
    echo 'Thanks, your file is uploaded.';
    
    ?>
    
    PHP:
    If you need more details, please, let me know..
     
    andy@pmr, Mar 5, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Yeah, this is really insecure. Don't use it like that in public.

    And on a further note, use move_uploaded_file() instead of copy(), it's made for this purpose...
     
    nico_swd, Mar 5, 2008 IP
  5. anisbd

    anisbd Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    83
    #5
    thanks all
     
    anisbd, Mar 5, 2008 IP