Solved

Uploaded files can't be moved

Posted on 2011-03-23
10
343 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 83

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

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 83

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
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…

728 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