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
Solved

Uploaded Image can't delete

Posted on 2004-08-17
3
624 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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