Jump to content

Upload files


jeremiorama

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.