Welcome Guest, Not a member yet? Register   Sign In
Really Strange Problem With Uploads
#1

[eluser]phpprogrammer[/eluser]
I just developed an entire application locally using XAMPP (Apache/PHP/MySQL)

Uploads worked great running locally. But when I put everything on the live server, suddenly uploads don't work anymore!

My script dynamically creates folders using mkdir() and then uploads images into those folders. The permissions are always set to 777.

Now, this is the really strange thing... When I moved the site, I moved some folders created on my local machine. There is no problem uploading to those folders. New folders can be created no problem. However, if I upload to a newly created folder, I get the message "ERROR: The upload destination folder does not appear to be writable." and nothing happens! I checked the permissions, and everything is 777.

Here are the 2 important lines from my code:

Code:
$config['upload_path'] = BASEPATH.'../img/'.$folderid;
$this->load->library('upload', $config);

When I echoed out the upload path, it gave me /var/www/vhosts/mysite.com/httpdocs/testing/system/../img/76. This path only works for uploading to the old folders.

What is the problem with CodeIgniter? I am pulling my hair out trying to get this to work! I'd really really appreciate any small bit of assistance Smile
#2

[eluser]Choo[/eluser]
You have to write a path correctly. You should have something like
Code:
'./img/'.$folderid
#3

[eluser]phpprogrammer[/eluser]
That method also returned the same error. What do I do now? I have searched CodeIgniter forums, Google, Yahoo and MSN to see if anyone else has had this problem. A few people have, but they never posted a solution for some reason.
#4

[eluser]_www_[/eluser]
Hello everybody,

./img/ seems not to be right.

BASEPATH.'img/'.$folderid looks better to me.

@phpprogrammer : As you already said, the problem is not about permissions. Its about your file path. Something there does not work as expected.
#5

[eluser]phpprogrammer[/eluser]
If it's a problem with the file path, why does the file path work correctly if $folderid is say 71 but not when $folderid is 76?? Both of them have the same permissions of 777.

Only difference is that they were created on separate servers.
#6

[eluser]phpprogrammer[/eluser]
SOLVED!!!

I checked the ownership of the folders in Linux, and they were set to "Apache" and group was "Apache". This ownership was causing the error, since it was the wrong owner for the folders.

I fixed it by turning PHP 'safe_mode' to OFF, and now file uploads work perfectly again.
#7

[eluser]simshaun[/eluser]
Be careful of just turning safe_mode off unless you are sure your apps have no holes in them...
#8

[eluser]_www_[/eluser]
Ok, sorry for my wrong suggestion. I didn't think of this possibility.

simshaun is correct by the way. Maybe you should enable safe_mode again and just set the correct owner. Looking at the manual of php you will see a nice example of a php script accessing the /etc/passwd file. It can do that, unless safe mode is on.

http://de.php.net/manual/de/ini.sect.safe-mode.php
"
When safe_mode is on, PHP checks to see if the owner of the current script matches the owner of the file to be operated on by a file function or its directory.
"
#9

[eluser]phpprogrammer[/eluser]
No problem. I am glad I finally found the solution after about 4 hours of pulling my hair out! Hopefully people having the same issue in the future will find some help through this thread. It really should be documented in CodeIgniter somewhere.

However, I really want to put safe_mode back on if it's possible to do so.

How do I get CodeIgniter to set the correct ownership when I make new folders and files? When I turn safe_mode on, it keeps setting the ownership to "Apache" when it should be something like "mysite"
#10

[eluser]Natebot[/eluser]
Wait, I'm confused. I'm under the impression that safe_mode is to be avoided and to concentrate instead on script and server security. Though I can see why you might want to make sure your app works for 3rd parties that have it turned on. In any case it will be gone come PHP 6.

Can you perform chown() to change the user? If the new directory is owned by 'www-data' aka the webserver user, then you should be able to change it to the user that is needed for uploading.




Theme © iAndrew 2016 - Forum software by © MyBB