Solved

Uploaded Image can't delete

Posted on 2004-08-17
3
621 Views
Last Modified: 2008-01-09
I have used the standard upload script for php to upload an image to a directory.  The script uploads ok, but I cant remove the file!  I have used my ftp client and the control panel from my host... I cant remove it?

This is the script I am using:

      $uploadDir = ROOT_PATH.'/img/'.$cat_dir['cat_dir'].'/'.$scat_dir['cat_sdir'];
      $uploadFile = $uploadDir . $_FILES['userfile']['name'];
      $fileName = $_FILES['userfile']['name'];
 
       if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))
      {
            $msg = 'Product upload failed';
            include ROOT_PATH.'/admin/pages/add_product.php';
            exit();
      }
      @chmod($uploadFile,777);
0
Comment
Question by:bliesveld
3 Comments
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 125 total points
ID: 11818140
move_uploaded_files only works if the files and directories being used are the same UID as the process that is running.  So if you want to move the files, you'll have to make sure that the web server created the destination directories using PHP instead of you creating them using your ftp or shell client.  

Another possibility it that your destination directory does not exist.   If your not running in safe mode, then the directory not existing is probably it.
0
 
LVL 1

Author Comment

by:bliesveld
ID: 11818329
turns out I can delete them by using unlink becouse it uses the same user that the file was created with.
0
 
LVL 3

Expert Comment

by:KarveR
ID: 11819154
remove the @ from the chmod() function to see what error it gives you, also depending on version of PHP, chmod requires the octal, so chmod($uploadFile,0777);
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

11 Experts available now in Live!

Get 1:1 Help Now