Jump to content

Archived

This topic is now archived and is closed to further replies.

jeremiorama

Upload files

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:

[code]
<?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>
[/code]

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 [url=http://ca3.php.net/manual/en/features.file-upload.php#features.file-upload.post-method]this PHP manual[/url] page for detailed explanation / reference.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.