Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Uploaded files can't be moved

Posted on 2011-03-23
10
Medium Priority
?
346 Views
Last Modified: 2012-05-11
I created an upload program that allows users to upload a file to my server. I used the PEAR HTTP/Upload.php function to write it to a directory named upload, which has 777 permission.

The files upload fine, but if I try to use an ftp program to move them to my laptop, I get a "Permission denide. Error code 3" error

This happens with zip files, .doc files and ai files.

Any idea why?

My processing code is below
set_time_limit (3000);
  ini_set('upload_max_filesize',155555555);
ini_set('post_max_size', 155555555);


$abpath = "/home/myuser/public_html/uploads/"; //Absolute path to where images are uploaded. 
require 'HTTP/Upload.php';
$upload = new HTTP_Upload('en'); // Language for error messages
$file = $upload->getFiles('userfile'); // return a file object or error
if (PEAR::isError($file)) { die ($file->getMessage());}// Check if the file is a valid upload
$properties = $file->getProp();
$extension = $file->getProp('ext');
if ($file->isValid()) { // this method will return the name of the file you moved, // useful for example to save the name in a database 
$file_name = $file->moveTo($abpath); 
if (PEAR::isError($file_name)) {  die ($file_name->getMessage()); }}

Open in new window

0
Comment
Question by:birwin
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35204805
PHP functions thru a web server are a different 'user' than you are.  Check to see if you are the 'owner' of the files.
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 35204824
what OS r u using? windows? you need to check the file permission on OS level.
0
 
LVL 6

Author Comment

by:birwin
ID: 35204852
Dave Baldwin: How do I check if I am classed as an owner of the file?

logudotcom: I am using windows 7 home premium 64 bit. How do I check the permissions at the OS level.

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35204868
If the server were a Unix server, it would show in the FTP listings.  I don't think it does on Windows though.  In Windows, I believe you can right click on the file name and select Properties and find the owner and permissions there.  "777 permission" is a Unix/Linux term, I don't think that it applies to Windows.
0
 
LVL 6

Author Comment

by:birwin
ID: 35204899
My server is a Linux box. It is a dedicated server running Centros 5 64bit. I am trying to copy the files to my Windows 7 64bit laptop, using WinSCP, although I also tried just using Explorer, and got the same errors. So the files are currently on the Linux box. The directory is 777, but the files show

The files themselves show as 660. If I try to change their permission level, I get the Error 3 Permission Denied. error.
0
 
LVL 14

Expert Comment

by:Phil Phillips
ID: 35204988
After line 8, try adding this:
$upload->setChmod(0666);

Open in new window


This should give you 0666 (rw-rw-rw) for the files themselves.  You probably only need 0664 though, but try 0666 for now.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35205000
That's a good sign that you're not the owner.  If you type "ls -al" at a command line in that directory, it will show you permissions and who the file owner and group are.  http://en.wikipedia.org/wiki/Ls
0
 
LVL 6

Author Comment

by:birwin
ID: 35209603
Decorum:

That code works, and files uploaded with it in the code are able to be moved or downloaded.

Any idea how I can download the exiting files?
0
 
LVL 14

Accepted Solution

by:
Phil Phillips earned 2000 total points
ID: 35209798
Easiest way would be to log into the server as root, and chmod the files.

If you can't... then you can just run the following script through the web:
<?php
$abpath = "/home/myuser/public_html/uploads";

if ($handle = opendir($abpath))
{
   $files = readdir($handle);
   while (false !== ($file = readdir($handle)))
   {
      if (is_file("$abpath/$file"))
      {
         chmod("$abpath/$file", 0666);
      }
   }
   closedir($handle);
}
?>

Open in new window

0
 
LVL 6

Author Closing Comment

by:birwin
ID: 35210910
Brilliant. A perfect solution for my current problem and a fix for future uploads.

Thank you.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

636 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