Punk Rock Geek Posted February 13, 2010 Share Posted February 13, 2010 The form works when I put the upload folder inside of the same directory as the php file. So: $target_path = "upload/"; Works. However, if the upload folder is in a parent directory, it does not work. I have tried: $target_path = "$_SERVER["DOCUMENT_ROOT"]/upload/"; And $target_path = "../upload/"; Help? Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/ Share on other sites More sharing options...
Anti-Moronic Posted February 13, 2010 Share Posted February 13, 2010 have you tried echoing the target_path? echo $target_path; make sure that is correct. Some servers add a trailing slash. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011814 Share on other sites More sharing options...
Punk Rock Geek Posted February 13, 2010 Author Share Posted February 13, 2010 Hmm, echoing $target_path when$ target_path= "$_SERVER["DOCUMENT_ROOT"]/upload/"; returns absolutely nothing. Even the "/upload/" part is missing. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011818 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 When your page contains $target_path = "$_SERVER["DOCUMENT_ROOT"]/upload/"; you are getting a blank page because that is a fatal syntax error and your code is never executed. When learning php, developing php code, or in this case debugging php code, please do it on a server with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you by displaying all the errors it detects. You will save a TON of time. Stop and start your server to get any change made to the master php.ini to take effect and confirm the settings afterwards in case the php.ini that you are changing is not the one that php is using. $target_path = $_SERVER["DOCUMENT_ROOT"] . "/upload/"; Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011828 Share on other sites More sharing options...
Anti-Moronic Posted February 13, 2010 Share Posted February 13, 2010 Yeh, sorry, I didn't even look at your syntax. Turn on error reporting. Also another way to encapsulate the whole definition is like so: $target_path = "$_SERVER[DOCUMENT_ROOT]/upload/"; Notice I removed the "" around DOCUMENT_ROOT. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011833 Share on other sites More sharing options...
Punk Rock Geek Posted February 13, 2010 Author Share Posted February 13, 2010 Okay, thanks, I changed target path to $target_path = $_SERVER["DOCUMENT_ROOT"] . "upload/"; I removed the extra / as well. When I echo it, I get: /var/www/html/upload/ However, the file is still not uploading. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011837 Share on other sites More sharing options...
Anti-Moronic Posted February 13, 2010 Share Posted February 13, 2010 Then it may be the way the script is handling the target path. You should turn on full error reporting and check your error logs. *something* will turn up as to why the file is not being uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011838 Share on other sites More sharing options...
Punk Rock Geek Posted February 13, 2010 Author Share Posted February 13, 2010 Got these errors when I turned on all PHP errors: Warning: move_uploaded_file(/var/www/html/upload/homepage01.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/*****/public_html/modules/add_file.php on line 94 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpVUAjh7' to '/var/www/html/upload/homepage01.gif' in /home/*****/public_html/modules/add_file.php on line 94 (***** kept blank for privacy reasons.) Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011848 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 Did you read the errors? They are telling you why the code does not work - No such file or directory And since the path list in the error /var/www/html/videos/ has nothing to do with code you have been posting in this thread, it will be a little hard for anyone to actually help you until you get your code to match what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011850 Share on other sites More sharing options...
Punk Rock Geek Posted February 13, 2010 Author Share Posted February 13, 2010 For simpicity's sake, I have been changing it to "upload" in this topic. (I just forgot to change it that time.) The name of the actual directory is videos. And yes, it exists in my root folder, and it is CHMOD'd to 777. $target_path = "videos/"; uploads correctly. And $target_path = $_SERVER["DOCUMENT_ROOT"] . "videos/"; returns the error in my previous post. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011855 Share on other sites More sharing options...
Anti-Moronic Posted February 13, 2010 Share Posted February 13, 2010 Does this directory exist: /home/*****/public_html/videos/ ? If so, just try that in the string on it's own: $target_path = '/home/*****/public_html/videos/'; Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011866 Share on other sites More sharing options...
Punk Rock Geek Posted February 13, 2010 Author Share Posted February 13, 2010 Cool, thanks, that worked. But is there any way I can call "/home/*****/public_html/" without typing it out? I'm going to be using this on different servers, and I want everything to be automatically defined. Quote Link to comment https://forums.phpfreaks.com/topic/191969-php-file-upload-form-doesnt-work/#findComment-1011870 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.