Jump to content

Recommended Posts

I think this forum is the best fit for this topic...

 

I've been coding in PHP for the better part of 2 years now and have a rudimentary grasp of what's going on. I recently was asked to administrate a friend's new Red Hat-based virtual server from GoDaddy, and things have been going swimmingly...until I attempted to hook in a PHP file upload, only to find that it will not move the files to the specified destination.

 

I'm getting an error of 0 for the $_FILES array, and when I run the script locally, it successfully move_uploaded_file() to the correct location (running Windows/WAMP Stack locally). However, duplicating this on the virtual server, there is no error or warning of any kind from move_uploaded_file(), it simply is not showing up in the correct directory. I've checked capitalization, I'm completely stumped.

 

I figure it's probably not a fault with PHP, as I've scoured the php.ini file and found all references to File Upload to be ON. It probably has something to do with directory permissions in Linux, but I'm still a novice at all that.

 

Any and all suggestions/help would be greatly appreciated. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/169957-solved-php-file-upload/
Share on other sites

The folder your trying to upload the files to most probably doesn't have sufficient permissions for writing.

 

Add the following at the top of your script

if(is_writable('/path/to/upload/folder/')
{
    echo 'Folder is writeable';
}
else
{
    echo 'Folder is not writeable';
}

And run it on your red-hat server. What is the output?

 

If its says not writeable then change the permissions of the folder to 0777

I ran the script (you forgot a right parenthesis, btw, took me 5 minutes to figure out why it wouldn't run :P). It was not writable. So I SSH into the server, I "chmod -R 0777 /path/to/webpage/root" (obviously with the correct path...) because there are a number of directories that need to be able to upload into, and the script says it is now writable.

 

....however the files are still not showing up after upload.

I've never gotton any errors of any kind, that's what baffled me. I have it spilling output trying to debut it.

 

print_r($_FILES);

 

no errors

 

I'm outputting the $path, $filename, etc, everything is correct, and the script runs with no issues locally on the Wamp stack. Just once I upload, it won't work. I did the chmod and the is_writable() now says all the directories are writable...but still nothing.

I figure it might have something to do with it being the wrong group. GoDaddy has CPanel which allows you to add a "Domain" to the server.

 

I addded the domain, and it created a new account with FTP permissions and such to the root HTML page and made that root folder the default folder when you go to the site itself, etc etc. What group should it be set to and how can I check if that's what it is or is not set to?

I'm trying to determine exactly WHERE the problem is occuring.

 

print_r($_FILES); produces:

 

Array ( [new_file] => Array ( [name] => geico_eyes.png [type] => image/x-png [tmp_name] => /tmp/phpjnTbKx [error] => 0 [size] => 12831 ) ) 

 

Does error = 0 mean it successfully arrived at /tmp/phpjnTbKx? Or does error 0 mean it received all the information and it SHOULD be in /tmp/phpjnTbKx??

 

Consequently, if the file cannot be moved via move_uploaded_file() should there be some kind of error or warning associated with it being the wrong permissions? I get no warnings or errors at all...where did it go wrong??

Somebody mark this as solved, as I'm a complete moron. I believe it was the initial chmod recommended in post #2 of this thread that solved the problem, but as I had complete bungled the original script trying to fix it in the first place, it wasn't working due to my own stupidity. I went through the code top to bottom and found some very stupid mistakes in regards to paths (what was I thinking...?) and it again works. Thank you for all your help and bearing with me.

 

So yea, mark as solved or something... :) And for future posters...check your destination paths. Wish I had...

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.