aspose file tools*
The moose likes PHP and the fly likes uploading to new directory fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "uploading to new directory fails" Watch "uploading to new directory fails" New topic
Author

uploading to new directory fails

Sami Dma
Greenhorn

Joined: Jul 16, 2013
Posts: 12
Hi, I am submitting a form (which creates a directory). That part parts works like a charm. Then, I am trying to upload my files in that directory. Both are going to be on the same page. Yet, the files refuse to go inside my create directory. I don't get it. This is the error message from the console.

Warning: mkdir() [<a href='function.mkdir'>function.mkdir</a>]: No such file or directory in <b>/home/*****/*****/*****/upload.php on line 7 has NOT been created

Warning: file_put_contents(images/$folder/saskype_bla.jpeg) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in /home/*****/*****/*****/upload.php on line 41
Something went wrong. Check that the file isn't corrupted

And my code for that part.


K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2370
    
    7

You are creating your directory 755? That's drwxr-xr-x. Check the owner of this directory against the apache user or whichever account runs apache HTTP server.

If the owner is not apache then issue a chown too then upload.

And welcome to the Ranch

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Sami Dma
Greenhorn

Joined: Jul 16, 2013
Posts: 12
I tried also with 777, but to no avail. As for your suggestion, how do you even do that? I've never heard of that before.


K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2370
    
    7

Sami Dma wrote:I tried also with 777, but to no avail. As for your suggestion, how do you even do that? I've never heard of that before.


Do what? chown in PHP? Just like you mkdir.

Further inspection, your $folder goes in the images folder. And from the error what does this evaluate to? images/$folder/saskype_bla.jpeg? Is this the correct path?
Sami Dma
Greenhorn

Joined: Jul 16, 2013
Posts: 12
No, it doesn't do that. I ensured myself that it wouldn't do that. It just doesn't save the file at all. With the code I have now, I can create a folder (in the same directory as my images folder), and I can save my image in the images folder.

Yes, as well as
Check the owner of this directory against the apache user or whichever account runs apache HTTP server.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2370
    
    7

To check what user Apache is running as, either in shell script (assuming unix/linux):
"ps aux | grep apache" or "ps aux | grep httpd" depending on the process name

Or you can use the php to find


If the newly created folders are owned by this user then you will be fine.
Sami Dma
Greenhorn

Joined: Jul 16, 2013
Posts: 12
OK... it returns to me a username from my database. It doesn't return anything resembling a linux line (or windows for that matter) ??? What the...
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2370
    
    7

Sami Dma wrote:OK... it returns to me a username from my database. It doesn't return anything resembling a linux line (or windows for that matter) ??? What the...


This is indeed odd. Apache HTTP server process is supposed to be system initiated process rather than a user process.

I actually somewhat tested your script substituting the $_POST[] stuff as strings:


For me, it works once I grant permission to public or everyone for the top folder (ie 757)

Note that the user Apache HTTP runs as is "_www" and my login user is "yktsang01"



[Thumbnail for Screen shot 2013-07-18 at 00.35.12 AM.png]

Sami Dma
Greenhorn

Joined: Jul 16, 2013
Posts: 12
I am doing some testing right now. I will let you know in the future how they go. I haven't come up with a solution to this dilemma yet. I am trying more things. I will keep you posted though
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: uploading to new directory fails