Jump to content

PHP File Upload Form Doesn't Work


Punk Rock Geek

Recommended Posts

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?

Link to comment
Share on other sites

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/";

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.