Jump to content

Uploading Image in a different directory


jtron85

Recommended Posts

Currently I'm trying to run a file which will upload images into the main directory. Although this files is currently situated in a dfferent directory and PHP is having problems locating the specified folders I've told it to place the files into.

Currently I've set the upload folder to be:

public_html/banners/header

And I've currently set my upload file as

public_html/admin

So with that I'm getting this message:

Warning: move_uploaded_file(banner/header/) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/user/public_html/admin/upload.php on line 203

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpABuUPi' to 'banner/header/' in /home/user/public_html/admin/upload.php on line 203
No image was uploaded.

I'm currently running this:
[code]//if the file type is not coorect
if (!($ad_file_type=="image/gif" || $ad_file_type=="image/png" || $ad_file_type=="image/jpg")){
//display warning
echo "There was no image uploaded because the file type was incorrect.<br>";
//end the rest of the coding
exit;
//else
} else {
//set up folder to be uploaded
$add="banner/header/$servfile_name";
if(move_uploaded_file ($ad_file, $add)){
//echo "Successfully uploaded the image<br><br>";
chmod("$add",0777);
}else{
//else no image was uploaded
echo "No image was uploaded.";
exit;
//complete if statements
};

$header_ad_filename = $add;
$filepath="http://www.domain.com/"; // ad on these
$header_ad_file = $filepath.$add;//files loc
$header_name = $_REQUEST["header_name"];//name given
$header_url = $_REQUEST["header_url"];//link given
$ad_file= $_REQUEST["ad_file"];
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29489-uploading-image-in-a-different-directory/
Share on other sites

i am guessing the script is in /admin
so what your trying to do is access the folder ./admin/banner/header/
try adding a ../ in front of banner.

and just for the record, your question confused me a tad. you said:
[quote]
Currently I've set the upload folder to be:

public_html/banners/header

And I've currently set my upload file as

public_html/admin
[/quote]

not quite sure what you mean but give the ../ a go.
Thanks for the reply. Sorry if my query wasn't clear.

Yes my script is in the "/admin" directory although what I'm trying to do is upload images into a completely different directory called "/banner/header/" which is not under the admin directory.

So my script is found in:

www.domain.com/admin

And where I want the images uploaded to is found in:


www.domain.com/banner/header
Thankyou both for your help but I'm still getting an error:

Warning: move_uploaded_file(/home/public_html/banner/header/top_banner.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/user/public_html/admin/upload.php on line 203

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpeet2uB' to '/home/public_html/banner/header/top_banner.gif' in /home/user/public_html/admin/upload.php on line 203

My code looks like this now:
[code]
if (!($ad_file_type=="image/gif" || $ad_file_type=="image/png" || $ad_file_type=="image/jpg")){
//display warning
echo "There was no image uploaded because the file type was incorrect.<br>";
exit;
} else {
//set up folder to be uploaded
$add="/home/public_html/banner/header/$ad_file_name";
if(move_uploaded_file ($ad_file, $add)){
echo "Successfully uploaded the image<br><br>";
chmod("$add",0777);
}else{
echo "No image was uploaded.";
exit;
//complete if statements
};

$header_ad_filename = $add;
$filepath="/home/public_html/banner/header"; // ad on these
$header_ad_file = $filepath.$add;//files loc
$ad_file= $_REQUEST["ad_file"];//file


[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.