I am having trouble getting my file upload to work. Up to now it has been working good, I recently had to upload a backup version of my website to the online server, but now the upload script does not work and, I suspect it may be a file upload permissions issue.

I understand I may have to inherit the folder/file permissions and ownership from my local host to the host server, but I not sure how to do this.

I cannot upload PDF files and/or images from the admin section upload form, but I can upload the files and/or images to the uploads folder by using either Filezilla FTP or by using the Cpanel File Upload with success.

I do not get any error message in the site admin upload form when submitting the form data, and the file/s in question are not present in the uploads folder or images folder.

The host server uploads folder permissions have been set at 0755, and the files permissions are set at 0644 in cPanel.

Nothing happens, and up until now everything worked ok. I have checked the script but I am not sure if everything is correct or not. It appears to be happening on all file uploads from the site admin file upload form.

I need file and/or image upload options in the admin panel for the site admin users to operate.

Can someone help me please? See below for example files:

upload_file.php - (for pdf & doc uploads):

    //Must go through login and be Admin    
    if(!$_SESSION['loggedIn']) {
        header('Location: index.php');
    $title = 'Upload File'; 
?><br /><br /><br /><br /> 

    <div id="uploadFile">
        <div id="uploadFiles">
                    $target = "uploads/"; 
                    $target = $target . basename( $_FILES['uploaded']['name']) ; 

                //This is our size condition 
                if ($uploaded_size >2950000){ 
                    echo "Your file is too large.<br>"; 
                //This is our limit file type condition 
                if ($uploaded_type =="text/php"){ 
                    echo "No PHP files<br>"; 
                //Here we check that $ok was not set to 0 by an error 
                if ($ok==0){ 
                    echo "Sorry your file was not uploaded"; 
                //If everything is ok we try to upload it 
                else { 
                    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ 
                    echo "&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
                          The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
                    // else { 
                    //    echo "Sorry, there was a problem uploading your file."; 
                <form enctype="multipart/form-data" action="upload_file.php" method="POST">
                        <legend>&#160;Upload File&#160;|&#160;<a href="viewFile.php" class="apageLinks">View File List</a>&#160;|&#160;
                                                              <a href="menu.php" class="apageLinks">Main Menu</a>&#160;|&#160;
                                                              <a href="logout.php" class="apageLinks">Log out</a>&#160;
                        </legend><br /><br />
                        Please choose a file:<input name="uploaded" type="file" /><br /><br /> 
                        <input name="submit" type="submit" value="Submit" class="form" /><br /> 
                </form><br /><br /><br /><br /><br />
<!-- End of page content -->
</html>                                                                                                                              It is a simple file upload script that I use to upload PDF files to the server. the files should be uploaded to the uploads folder in the admin section of the website, and these files are generally small in size, in fact I also use a similar script to upload images to the host sevrer.
2 Years
Discussion Span
Last Post by davBro


This is going to be due to the settings in Apache that CPanel sets up. Is your new server running CPanel also if not it gets trickier. If it is running CPanel then you should set the user and group o the user id that owns the web site. If you can run ls -la /home/<your user> from a ssh connection and post the results I can give you an idea of the command to use to get it to work. For the time being you could do a chmod 775 on the upload directory so that the group can write and it might work. Need to see the actual listings to get a good idea.


Hi - I've encountered something similar before and it was beyond frustrating especially when I didn't get an error aswell.

Someone pointed out that it was indeed the file permissions and I was using FileZilla at the time. So I changed the folder's permission to where I'm uploading to 777 and it all worked 100%. Maybe this can work for you.

Edited by Phillamon


Hi Phillamon, yes I know about using 777 but by using that permission wouldn't it be too unsecure.

I only want the site administrator and Authenticated Users to have write permisssions to upload files (pdf, doc and images) to the server, and not everyone which is why I had set the permissions to 755, and at present, even that doesn't work.

It's frustrating, as this problem appeared out of the blue and I am having a lot of dificulty know how to fix it.

Cheers, davBro

Edited by davBro


check if folder permission is 755
and check Apache user which in Ubuntu is www-data
to find out Apache user
ps aux | grep apache
and do this command
chown -R www-data /path/to/folder

Edited by OsaMasw


Howdy OsaMasw,

The folder permission is 755 and the fle permissions are 644.

I checked to see who the Apache User is, and it is listed as Nobody.

I do not understand this, it's getting a bit complicated for me how would I change from Nobody to an admin User (with full permissions) to enable file and image uploads for whichever admin user is uploading the file/image?

I now realise why I cannot upload files and/or images, but I do not know how to fix it, or inherit the localhost permissions to the host server?

Have you a fix for this please?


ls -l /path/of/folder
you should see the user who can manage this folder, if its not Nobody
chown -R Nobody /path/to/folder


Thanks OsaMasw, I'll give that a go and will let you know how it goes.

Cheers, davBro

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.