Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Uploaded files can't be moved

Posted on 2011-03-23
10
Medium Priority
?
347 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
  • 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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 15

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 15

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 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