[SOLVED] uploads folder, where can i put it!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

uploads folder, where can i put it!

Post by C_Calav »

hi guys,

when you upload a file and you move it from the temp folder say to a uploads folder, does the uploads folder have to be in the same dir as the upload script?

this seems to be the case for me!
i tried putting the uploads folder under page 1 and it wont work, only works when under page 2, where the upload script is.

thanx!

site
|__ Page 1
|
|
|__ Page 2/upload script, uploads
Last edited by C_Calav on Mon Jun 28, 2004 10:56 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

It can be anywhere you like as long as the webserver user has permissions to write to that directory.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx again,

thats what i thought. i have all the needed permissions and i got it working but i need the folder to be in a diff place.

ill keep timkering round with it!

thanx
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

so having it in a diff dir branch doesnt matter?

just cant get to work eliminating problems!

does it matter if i type

/Pics/
Pics/
http://www.website.com/Pics/

Code: Select all

<?php
	move_uploaded_file($_FILES['file']['tmp_name'],
	Pics/' . $_FILES['file']['name']);
	echo 'File has been stored in your uploads directory.';
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

move_uploaded_file($_FILES['file']['tmp_name'], '/the/full/path/to/Pics/'.$_FILES['file']['name']);
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

ERROR:

Warning: move_uploaded_file(): open_basedir restriction in effect. File(/the/full/path/to/Pics/VVV.jpg) is not within the allowed path(s): (/var/users:/home/users:/tmp:/var/www/defaults:/usr/local/apache-custs/defaults:/usr/local/lib/php) in /var/users/modelair/modelaircraft.co.nz/htdocs/admin/insert.php on line 46
File has been stored in your uploads directory.

and heres my script...the Pics folder has full permissions

BTW it works fine when the Pics folder is in the same dir as the upload script.

Code: Select all

<?php
if (($_FILES['file']['size'] > 1000))
{
echo 'Uploading ' . $_FILES['file']['name'] . ' (' .
$_FILES['file']['type'] . ', ' .
ceil($_FILES['file']['size'] / 91024) . ' Kb).<br />';

if (file_exists('Pics/' . $_FILES['file']['name']))
{
echo $_FILES['file']['name'] . ' already exists. ';
echo 'Please delete the destination file and try again.';
}

else
{
move_uploaded_file($_FILES['file']['tmp_name'], '/the/full/path/to/Pics/'.$_FILES['file']['name']); 
echo 'File has been stored in your uploads directory.';
}

} 
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

File(/the/full/path/to/Pics/VVV.jpg) is not within the allowed path(s):
er...your supposed to replace /the/full/path/to/Pics with your actual full path to it. As your server has open_basedir in effect Pics will have to be in one of these directories:
/var/users:/home/users:/tmp:/var/www/defaults:/usr/local/apache-custs/defaults:/usr/local/lib/php
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

whoops! silly me! sorry

i get ya, but where are these directories?

/var/users:/home/users:/tmp:/var/www/defaults:/usr/local/apache-custs/defaults:/usr/local/lib/php

what would be an example?

thanx for all ur help and putting up with me this is very confusing for me
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

ok, i'd just create a directory called Pics in your document root, that's the directory your index.php file is in.
Then use :
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/Pics/'.$_FILES['file']['name']);

Make sure the Pics directory has sufficient permissions.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

Warning: move_uploaded_file(): open_basedir restriction in effect. File(/etc/httpd/htdocs/Pics/GAG.jpg) is not within the allowed path(s): (/var/users:/home/users:/tmp:/var/www/defaults:/usr/local/apache-custs/defaults:/usr/local/lib/php) in /var/users/modelair/modelaircraft.co.nz/htdocs/admin/insert.php on line 38
File has been stored in your uploads directory.

still getting a error
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Looks like the host has some funky symlinking going on (stooopid open_basedir).
So try:
move_uploaded_file($_FILES['file']['tmp_name'], '/var/users/modelair/modelaircraft.co.nz/htdocs/Pics/'.$_FILES['file']['name']);

(presuming you created the Pics dir in /var/users/modelair/modelaircraft.co.nz/htdocs/)
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

that did it! thanx you very much for your help today :D
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

No problem, glad you got it to work ;)
Post Reply