Click to See Complete Forum and Search --> : Help Uploading files to the server
Durbs
08-23-2004, 08:35 AM
Hi I'm trying to allow users to upload images to a specific folder on the server, and at the same time stroe information about it in the database. I've created a form using <input type="file"............> that allows the user to browse their system for images to upload, but am not sure what exactly to do next to get the file to upload.
I also have a general query on how to use $_POST, $_SERVER etc. I've read quite a bit on these in various books and still don't quite understand what they mean and their function when used in forms. For example when you create a textfield using <input type="text" name="title" size="40" value="$_POST['title']" /> what exactly does that do? If using <form action="$_SERVER['PHP_SELF'];" method="post"> does it post the data entered into field to the same page, if so is it enable you to refer to the data entered you simple use 'title'? As you can probaly tell i'm a little confused. Hope that all makes sense..
Cheers,
Durbs
Durbs
08-23-2004, 08:50 AM
Have just found this tutorial (http://www.zend.com/zend/spotlight/uploading.php) on file uploading, so i think i've got it covered. I'm still confussed about the other bit tho if anybody would like to explain it in plain English, so that ever-so-slightly dense me can understand? Anybody?
Cheers,
Durbs
NogDog
08-23-2004, 09:26 AM
The $_POST['key'] idiom is used to access any variables sent to the current page by a form on the calling page which used the POST method. Normally if, for instance, your calling page has a field called "name", we can just reference it as $name in the called page. But we can also call it $_POST['name'] (or $_GET['name'] if GET method was used) which can serve two purposes: (1) it makes the source of this variable more obvious, and (2) it can avoid variable name "collisions", such as if you have a session variable named 'name' as well (which you would then differentiate by calling $_SESSION['name']) and a $name variable in an included file.
Durbs
08-23-2004, 05:30 PM
Cheers NogDog, that clears it up for me.
In the tutorial that i posted a link to above you have to set the upload path that the file stored in the upload_temp_dir will be moved to. It is set using the string:$uploadpath = '/path/to/store/uploaded/files/'; On my server (kindly provided by liquidsix.com (http://www.liquidsix.com)) what is this path relevent to (ie. would it be just from my root directory provided to me, or would it be from, say, C:\domains\mydomain\insert\path\here - it's a windows server by the way)?
Will be experimenting with different methods but if anybody is in the know and would like to save me some time, feel free:D
edit:
One other thing, to get the source (ie. the file name, and the temp directory where it is after uploading) it uses:$source = $HTTP_POST_FILES['file1']['tmp_name'];but i read that php5 is leaving long-form predifined variables out in favour of $_POST['']. If this is so (and if this applies to $HTTP_POST_FILES) what is the short form?
Cheers,
Durbs
NogDog
08-23-2004, 05:48 PM
Last file upload thingy I did in PHP was under PHP3, so I went to php.net to refresh my memory. Found this page, which may clear things up a bit (looks like there is now a $_FILES array you can use): http://us4.php.net/features.file-upload
Durbs
08-23-2004, 06:39 PM
Success:D Cheers buddy.