Jump to content


Photo

Upload files


  • Please log in to reply
3 replies to this topic

#1 jeremiorama

jeremiorama
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationQuébec, Québec

Posted 31 July 2006 - 05:19 PM

Hi there,

I'm looking at some PHP-designed sites that let us upload, let say, images, from our hard drive to their system. I would like to know how this is done. I haven't found anything in PHP that would let me do this. Anyone has an idea?

Thanks,

-Jeremie

-Jeremiorama

#2 r3gan

r3gan
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 31 July 2006 - 05:32 PM

This can be done by including a form on your page that submits to a PHP page running on your server.  This can be the same PHP page as the form exists in or not.  Here's a simple example:

<?php
//
// uploaded file processing
//
if (is_uploaded_file($_FILES["flImage"]["tmp_name"])) {
    $newName = "some/path/filename"
    if (!move_uploaded_file($_FILES["flImage"]["tmp_name"], $newName)) {
      $pAction1Result = -1;
    }
    else {
      $pAction1Result = 1;
    }
}
?>
<form id="frmImgUpload" name="frmImgUpload" enctype="multipart/form-data" method="post" action="<? print $_SERVER["PHP_SELF"];?>">
<input type="file" name="flImage" id="flImage" size="90" class="text">
<input type="button" name="btnImgSubmit" id="btnImgSubmit" value="Upload Image" onclick="document.frmImgUpload.submit();">
</form>

Files uploaded from a form are stored in the $_FILES superglobal variable, and can be checked/moved with the is_uploaded_file() and move_uploaded_file() pre-defined PHP functions.  Check out this PHP manual page for detailed explanation / reference.

#3 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 31 July 2006 - 05:48 PM

you can either use the above script or the handling file uploads chapter in PHP manual.
And some free space providers are Yahoo Breifcase, Rapid share, My space, and etc.
I am a PHP Guru, ask me questions if you want to

#4 jeremiorama

jeremiorama
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationQuébec, Québec

Posted 01 August 2006 - 01:40 PM

Thanks guys! Someone told me this wasn't done with PHP once, but I didn't remember what. I guess he was wrong.
Thanks!
-Jérémie

-Jeremiorama




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users