...

View Full Version : php upload problem



Scrowler
05-24-2004, 10:08 AM
$uploaddir = 'http://www.websiteurl.com/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
} else {
print "Error uploading file!";
exit;
}

$url = $_FILES['userfile']['name'];

mysql_query("INSERT INTO pics (URL) VALUES ('$url')") or die("Error inserting picture!<br><br>".mysql_error());
echo 'Picture has been added!';

it dies... why doesnt it work?

firepages
05-24-2004, 10:30 AM
did you suppy an enctype in your form ?
<form name="bella" method="POST" action="?" enctype="multipart/form-data"> etc ?

Scrowler
05-24-2004, 10:37 AM
yeah, still giving an error

firepages
05-24-2004, 04:33 PM
DOH , should have spotted this the first time (but the form thing is the usual reason)
$uploaddir = 'http://www.websiteurl.com/';

you can't copy to a URL use the filepath instead ..

$uploaddir='/home/user/uploads/';

and of course make sure the directory has the correct permisions

Scrowler
05-25-2004, 08:42 AM
DOH , should have spotted this the first time (but the form thing is the usual reason)
$uploaddir = 'http://www.websiteurl.com/';

you can't copy to a URL use the filepath instead ..

$uploaddir='/home/user/uploads/';

and of course make sure the directory has the correct permisions

how do i know what the filepath is?
i want to upload to the main directory

thunderbox
05-25-2004, 10:26 AM
it si not very wise to upleoad into the main directory, so i reccomend just making a folder called "upload" so your $uploaddirectory will be "/upload"

Scrowler
05-26-2004, 12:17 PM
but where do i get all the var/www stuff from

firepages
05-26-2004, 01:23 PM
if you are on a unix machine then chances are the root directory path is

/home/$your_account_name/public_html/

but you can probably use

$_SERVER['DOCUMENT_ROOT'].'/uploads/';

simply <?echo $_SERVER['DOCUMENT_ROOT'];?> if you want to know what the path is , in the case of PHP as a CGI you may need another variable.


<?
echo'<pre>';
print_r($_SERVER);
echo'</pre>';
?>


to see them all !

Scrowler
05-27-2004, 05:52 AM
thank you vry much i will try this

Scrowler
05-27-2004, 06:00 AM
/home/********/public_html/uploads/Error uploading file!

I added in

echo $uploaddir;

after the line that defines it:

$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/uploads/';

I've also CHMODded the folder to 777 and I was trying to upload a file called barcode.gif

any help?

firepages
05-27-2004, 07:15 AM
Hi add ,

<?echo '_FILES array = <pre>';print_r($_FILES['userfile']);echo '</pre>';?>

to see what the contents of $_FILES['usefile'] actually contains , it will contain an error message if one exists , if its empty , check your form !

Scrowler
05-28-2004, 06:04 AM
thanks for that little peice of code, ive left that in the script as debugging information. its working now, turns out i had put enctype="multipart/form-data" in the wrong tag :o

thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum