?
Solved

Uploaded files can't be moved

Posted on 2011-03-23
10
Medium Priority
?
344 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

752 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