jeremiorama Posted July 31, 2006 Share Posted July 31, 2006 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 Quote Link to comment Share on other sites More sharing options...
r3gan Posted July 31, 2006 Share Posted July 31, 2006 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. Quote Link to comment Share on other sites More sharing options...
Chetan Posted July 31, 2006 Share Posted July 31, 2006 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. Quote Link to comment Share on other sites More sharing options...
jeremiorama Posted August 1, 2006 Author Share Posted August 1, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.