Upload files

software development

#1

Hey have any of you successfully uploaded files from a web interface?
I am trying, without success, to get files to upload to a folder on my site. I can’t even get my script to echo the temp folder. Here is what I have:

<?php $source = $HTTP_POST_FILES['file1']['tmp_name']; echo 'hit'.$source; $uploaddir = "upload"; if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); } print "Your file has been uploaded successfully! Yay!"; ?>

My folder, “upload” has the permissions set to 777. I really am stumped. I had previously gotten files to upload as blobs to MySQL, but then couldn’t get the images to display in my pages. And, I read that it is preferrable to upload to a folder and just store the path.

I am relatively new to php and I am stuck! Can anyone shed any light on this?


#2

You should be using $_FILES instead of $HTTP_POST_FILES (deprecated since PHP4).


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

Oh, thanks. Well, I changed that, and it still doesn’t write anything out in response. Does anyone know if it is possible to upload files to a dreamhost hosted site? Do their servers allow it? Thanks, Donna


#4

I do it with images all the time, so it should be straightforward. Make sure your form has the attributes of method=“post” and enctype=“multipart/form-data”. I use the following:

$userfile_name = $_FILES['userfile']['name']; // temporary filename $userfile_tmp_name = $_FILES['userfile']['tmp_name']; // temporary path and filename $filename = "../path/to/upload/dir/$userfile_name"; move_uploaded_file($userfile_tmp_name,$filename);--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]