Jump to content

File Upload


jgingras
 Share

Recommended Posts

Hi Everyone,

I just had a question on file upload, im trying to upload a file and when I check the is_uploaded_file(), it says that it worked correctly, but I dont know how to set the path to move_uploaded_file. I created a folder in my public_html directory, but dont really know how to proceed from here? Let me know if anyone had a suggestion.

Link to comment
Share on other sites

The path you'd need to use for a subfolder in your public_html directory would be:

>/home/cpanelName/public_html/my_sub_folder

...where 'cpanelName' is your CPanel username, and 'my_sub_folder' is the name of the subfolder you created.

 

I don't know if that totally answers your question, but I hope it helps! :)

Link to comment
Share on other sites

Ok,

The error that im getting is

 

>Warning: move_uploaded_file(/home/cpanelname/public_html/foldername/filename): failed to open stream: Permission denied in /home/cpanelname/public_html/file.php on line 39

Warning: move_uploaded_file(): Unable to move '/tmp/tmp_filename' to '/home/cpanelname/public_html/ProjectDocs/filename' in /home/cpanelname/public_html/file.php on line 39

 

Do I need to do something in cPanel to allow my user to upload files? Im new to php and things like that.

 

Thanks for your help.,

-Jacques

Link to comment
Share on other sites

Ok,

The error that im getting is

 

>Warning: move_uploaded_file(/home/cpanelname/public_html/foldername/filename): failed to open stream: Permission denied in /home/cpanelname/public_html/file.php on line 39

Warning: move_uploaded_file(): Unable to move '/tmp/tmp_filename' to '/home/cpanelname/public_html/ProjectDocs/filename' in /home/cpanelname/public_html/file.php on line 39

 

Do I need to do something in cPanel to allow my user to upload files? Im new to php and things like that.

 

Thanks for your help.,

-Jacques

 

Hi Jacques,

 

Is it safe to assume that when your error message says "cpanelname" that you actually are using your cPanel login name?

 

For example, if your cPanel login name is abcxyz and your subfolder is named 'blog' then you should really using the following path:

 

/home/abcxyz/public_html/blog

 

I'm just checking, because sometimes users forget that they have to customize the cPanel name. You probably didn't have this problem, but it never hurts to check... :thumbup1:

Edited by abinidi
Link to comment
Share on other sites

Is ProjectDocs actually that name?  The servers are case sensitive.  And is that folder permissions set to 777?

I did use the correct case for the folder, how do I set the permission to 777? Also, what would happen if I put a path of a folder that hasn't been created? Would it automatically create it, or would I have to create the folder ahead of time? And, if this is the case, is there a way to create the folder and set its permission using php?

 

Thanks,

Jacques.

 

P.S. and yes. i did change cpanelname to my username.. thanks! :angry:

Link to comment
Share on other sites

You can use mkdir('/pathname'); to create the directory, and chmod('/pathname', 0777); to set its permissions.  The directory will be owned by the user 'nobody' instead of you though, since PHP scripts run as that user.

David, what are the implications of having the directory be owned by "nobody"?

Link to comment
Share on other sites

For a directory owned by 'nobody' where the permissions not set to 0777 (such as 0755), you would not be able to create or delete files and subdirectories in that directory from your FTP program or CPanel.

 

If a file is owned by 'nobody' and its permissions are not set to 0777 (such as 0644), you would not be able to edit the file except via a PHP script.

 

You would also not be able to change the permissions on a file or directory owned by 'nobody' using your FTP program or CPanel, as you have to own the file or directory in order to change its permissions. Again, you'd have to use a PHP script to change permissions on a file or directory owned by 'nobody', or submit a ticket to the Help Desk (who can change the owner and permissions on any file as the 'root' superuser).

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...