Solved

Uploaded Image can't delete

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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
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 …

635 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