Solved

File upload problem (PHP/Apache/Linux)

Posted on 2004-10-01
8
396 Views
Last Modified: 2012-06-21
I know this is a common problem, but the solutions I've found so far do not work. I'm having a error like this: Warning: move_uploaded_file(/home/aixa/www/Phoenix/products/lite-table_main.jpg): failed to open stream: Permission denied in /home/aixa/www/Phoenix/cpanel/cpanel_functions.inc on line 249

The folder where I want to put the file into has the correct permissions. So does its parent folder, and the same is true for the temp folder. The code I have is as follows:

function file_upload($dest){
   if($dest=="products"){  
      $up_filename = $_FILES['nu_img']['name'];
      $up_dir = "/home/aixa/www/Phoenix/products/";
      $up_tmpname = $_FILES['nu_img']['tmp_name'];
   }
   if($dest=="restore"){
      $up_filename = $_FILES['nu_bk']['name'];
      $up_dir = "/home/aixa/www/Phoenix/cpanel";
      $up_tmpname = $_FILES['nu_bk']['tmp_name'];
   }
   $up_file = $up_dir . $up_filename;
   if (move_uploaded_file($up_tmpname, $up_file)) { # If uploading successful
      if ($dest == "products"){
         if ($_FILES['db_back']['type'] == "image/jpeg"){ # If correct file type
            $salida = $up_filename;
         }
         else { # Error handling for wrong filetype
            echo "javascript:alert('Wrong or Invalid File');";
         }
      }
      if ($dest == "restore"){
         if ($_FILES['db_back']['type'] == "text/plain"){ # If correct file type
            $salida = $up_filename;
         }
         else { # Error handling for wrong filetype
            echo "javascript:alert('Wrong or Invalid File');";
         }
      }
   }
   else { # Error handling for unsuccessful upload
      $salida = "Error!";
   }
   return $salida;
}

# and I call this function like this:

 $uploaded_file=file_upload("products");

after I sent a form that includes the part:

<form ...>
<input name="MAX_FILE_SIZE" value="1300000" type="hidden"> Upload new image: <input name="nu_img" class="text" type="file">
</form>

Any comments? what am I missing?
0
Comment
Question by:aixarat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 94 total points
ID: 12204219
I only get this error-message if that directory exits, but is not writeable by the webserver user. So how are the permisisons on the directory /home/aixa/www/Phoenix/products/ and under which user is the webserver running? If that directory is writeable by the webserver user It will overwrite any file in that directory regardingless of the permission of that file.

So far I can't locate any errors in that script which might cause that error.

So recheck the permissions again
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 93 total points
ID: 12204881
Usually the permission is set to 666 so the directory has write access but commonly it must be 777 for the upload to work.

As long as your script and server is secure 777 permission will not be a problem.
0
 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 93 total points
ID: 12206668
Hi aixarat

Are you using CPanel to manage your site?

Don't know if you already know this.

When you login to Cpanel, you can goto to the "File Manager"
In the file manager, browse down to the actual folder that you would like to upload the file to.
Click on the name of the folder and not the image of the folder. On the right of the window (Maybe different on different Cpanel versions) select "Change Permissions" and then check all the checkboxes and then click "change". The folder now should have "777" as the permission.

Note: you have to set "777" to the actual folder and not its parent folder.

Hope this helps

j311y:)
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12483840
We all provided suggested solutions, but no reply from author :(
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12483858
I recommend split between the three participants.

Its fairly likely that the problem was as i said above, the permission was set as 666 not 777 and thats what everyone was touching on.

side note: Venabili, thanks for your efforts cleaning up the PHP TA, its appreciated.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Log in through ID 5 36
Checking https returns 301 21 55
php subtract from date 2 27
Set a time limit on Wordpress Cookie function. 3 10
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question