Example: If I had a town with the ID of 6, the upload directory would be public/uploads/towns/6. This works perfectly fine as the directory is created when the town is created. I have nearly the exact same function for hotels except the path is public/uploads/hotels/[ID]. I have set the permissions to 777 just to remove that from the equation for now.

I cannot figure this out as they are both very similar functions. Here is the hotel upload code:

Is all that example code necessary to answer the question? I doubt so. Provide a short example that reproduces the problem.
–
cweiskeApr 24 '11 at 19:01

Does the target directory really exist? Where do you create it? Are both scripts in the same directory?
–
Pekka 웃Apr 24 '11 at 19:04

@cweiske That's all the code that is required as the hotel upload script as the do_upload method always returns false. With the HTML form I submit a simple image that meets all the requirements.
–
SamVApr 24 '11 at 19:05

@Pekka both scripts are in the same controller, and the target directory does exist as I have checked many times with an FTP client. If it doesn't exist a different error shows up anyway.
–
SamVApr 24 '11 at 19:06

@Sam can you try is_writable() on the directory?
–
Pekka 웃Apr 24 '11 at 19:12

3 Answers
3

Your code doesnt check the chmod works. For example, by default, apache loves to run as its own user or nobody, not you as a user. So, the chmod in your file may find the user its currently running as doesnt own the file, so the chmod fails.

First thing I would check would be the user PHP thinks it runs as, and the owner of the file.

There is the is_writable function, you could check the directory is writable.

I don't even need to chmod it as the directory is already 777, I have read about that but I don't understand why the town_upload function works and the hotel function doesn't as they are basically the same thing. Just checked if it is writeable and it returned true. Really don't know what's going on!
–
SamVApr 24 '11 at 19:14

Can you do echo $config["upload_path"]; after you set it so that we can see it's what you expect it to be
–
DormouseApr 24 '11 at 19:16

It returned "./public/uploads/hotels/7" and Filezilla says its there as well.
–
SamVApr 24 '11 at 19:29

also check safe_mode command in php.ini file it should be in off mode.
–
DormouseApr 24 '11 at 19:31

Master value is off, but local is on? Why does the other function work then??
–
SamVApr 24 '11 at 19:47

I just ran into the same problem and found a possible reason for this behaviour. In my case, I had created the upload directory a while back. I upgraded php which put in a new php.ini file that had safe_mod = On. And now when I recreated the directory after erasing it, the new php parameters kicked in throwing this error message.

Could it just be possible that you created the town dir tree before a PHP upgrade and your hotel dir tree afterwards?