Solved

Uploaded files can't be moved

Posted on 2011-03-23
10
338 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 82

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
 
LVL 82

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

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 82

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 12

Accepted Solution

by:
Phil Phillips earned 500 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now