Solved

Uploaded Image can't delete

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

816 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

8 Experts available now in Live!

Get 1:1 Help Now