jtron85 Posted December 5, 2006 Share Posted December 5, 2006 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/headerAnd I've currently set my upload file as public_html/adminSo 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 203Warning: 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 203No 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 More sharing options...
JasonLewis Posted December 5, 2006 Share Posted December 5, 2006 i am guessing the script is in /adminso 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/headerAnd I've currently set my upload file aspublic_html/admin[/quote]not quite sure what you mean but give the ../ a go. Link to comment https://forums.phpfreaks.com/topic/29489-uploading-image-in-a-different-directory/#findComment-135333 Share on other sites More sharing options...
jtron85 Posted December 5, 2006 Author Share Posted December 5, 2006 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/adminAnd where I want the images uploaded to is found in:www.domain.com/banner/header Link to comment https://forums.phpfreaks.com/topic/29489-uploading-image-in-a-different-directory/#findComment-135368 Share on other sites More sharing options...
genericnumber1 Posted December 5, 2006 Share Posted December 5, 2006 you could also do an absolute path to where you want to upload it but like projectfear suggested "../" also works to go to parent dir...[code=php:0]$filepath = '/home/public_html/banners/header/'; // your path of course[/code] Link to comment https://forums.phpfreaks.com/topic/29489-uploading-image-in-a-different-directory/#findComment-135370 Share on other sites More sharing options...
jtron85 Posted December 5, 2006 Author Share Posted December 5, 2006 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 203Warning: 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 203My 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] Link to comment https://forums.phpfreaks.com/topic/29489-uploading-image-in-a-different-directory/#findComment-135383 Share on other sites More sharing options...
jtron85 Posted December 5, 2006 Author Share Posted December 5, 2006 Not too sure of what was causing it although I went over the script and changed the $add variable to:$add="/home/bikebuy/public_html/banners/header/$ad_file_name";Now everything's sweet. Link to comment https://forums.phpfreaks.com/topic/29489-uploading-image-in-a-different-directory/#findComment-135408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.