AceOfJames Posted January 26, 2009 Share Posted January 26, 2009 I want this file upload script to upload a file to a directory outside of the directory that the upload script is in. Where in this code would I put the path to the destination directory? <?php // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; $result = 0; $target_path = $destination_path . basename( $_FILES['myfile']['name']); if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { $result = 1; } sleep(1); ?> Thank you in advance! AceOfJames Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/ Share on other sites More sharing options...
corbin Posted January 26, 2009 Share Posted January 26, 2009 // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746298 Share on other sites More sharing options...
AceOfJames Posted January 26, 2009 Author Share Posted January 26, 2009 I saw that but what is the syntax to change that part of the script? I want to put the uploaded file in ../images (relative to where the script is) How would I define that? Thanks! AceOfJames Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746299 Share on other sites More sharing options...
cooldude832 Posted January 26, 2009 Share Posted January 26, 2009 I always use an absolute address which never gives me issues my path <?php $tmp_name = "Example.txt"; $upload_path = $_SERVER['DOCUMENT_ROOT']."/uploads/".$tmp_name; ?> So ideally $_SERVER['DOCUMENT_ROOT'] is my www folder so to speak of. Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746303 Share on other sites More sharing options...
AceOfJames Posted January 26, 2009 Author Share Posted January 26, 2009 Thanks for the reply cooldude... How does that work with how the destination path is already defined? $destination_path = getcwd().DIRECTORY_SEPARATOR; Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746310 Share on other sites More sharing options...
cooldude832 Posted January 26, 2009 Share Posted January 26, 2009 Thanks for the reply cooldude... How does that work with how the destination path is already defined? <?php $destination_path = $_SERVER['DOCUMENT_ROOT']."/SUBFOLDER HERE/".$filename; ?> Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746314 Share on other sites More sharing options...
AceOfJames Posted January 26, 2009 Author Share Posted January 26, 2009 That worked perfectly! Thanks cooldude832! AceOfJames Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746317 Share on other sites More sharing options...
cooldude832 Posted January 26, 2009 Share Posted January 26, 2009 That worked perfectly! Thanks cooldude832! AceOfJames Second scope question of the night. When in doubt go absolute the $_SERVER array is very useful in a lot of cases. If you have a chance make a file that just has <?php print_r($_SERVER); ?> and then in firefox view its source and look at all the goodies in there you will be shocked. Quote Link to comment https://forums.phpfreaks.com/topic/142435-solved-destination-directory/#findComment-746318 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.