Jump to content

Upload files


jeremiorama

Recommended Posts

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
https://forums.phpfreaks.com/topic/16121-upload-files/#findComment-66484
Share on other sites

Archived

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

×
×
  • 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.