Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Uploaded Image can't delete

Posted on 2004-08-17
3
Medium Priority
?
630 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
[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
3 Comments
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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