Trouble with deleting files from my hosts server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grahamblake28
Forum Newbie
Posts: 1
Joined: Sun May 11, 2003 4:48 am

Trouble with deleting files from my hosts server

Post by grahamblake28 »

:? Hi,

I'm fairly new to the php thing so bear with me.

I've upload an image to a folder on my hosts server and also written the file name to a database in the process using the PHP pure upload extension from DMX. I also have created a page where I can delete the database entry. I am trying to delete the file from the server on this page also, from the same button, i.e. on click kills DB entry and file at the same time.
The databse deletion is complete but I am stuck on the file deletion.

The code looks something like this

$tempFolder = main_photos;

(main_photos is the name of the fiolder where I am storing the images)

$tempFile = $row_rs_main_photo['main_photo_filename']);

(the database entry which stores the filename)

$tempPath = $tempFolder."/".$tempFile;

(concat' folder and filename for file path)

if(isset( $Submit )) {
unlink ("$tempPath");
}

(the file deletion bit using PHP's unlink())

This does not work.
If I replace the database entry with a hardcoded filename of a file I know I want to delete it works and deletes the file!

Is the problem something to do with the formating on the retreived filename from the database?

Or is it possible that the database record is deleted before the value can be reteievd to delete the image?

I'm well stuck.

Any help on this one would be much appreciated

binaryjunk
UK
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I noticed that you have a parenthesis at the end of this line:
$tempFile = $row_rs_main_photo['main_photo_filename']);

The code should be:
$tempFile = $row_rs_main_photo['main_photo_filename'];


This may just be a small mistake when copying from your original code.
Image Image
Post Reply