User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,396 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,792 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2232 | Replies: 22
Reply
Join Date: Feb 2008
Posts: 297
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #11  
May 7th, 2008
i have got the images coming through with the email. the code now looks like this

$image = "";
$broad_img1= "";
$path= 'http://www.acmeart.co.uk/mercury';
$web_image_folder = 'image/thumbs';
$exts = array('jpg', 'png', 'gif', 'jpeg');
$image_name = 'thumb_image1';


// check for each extension
foreach($exts as $ext) {
   if (file_exists($web_image_folder.'/'.$image_name.'.'.$ext)) {
     $image = $image_name.'.'.$ext;
   }
}

// check if we have an image
if ($image != "") {
    // ok we have the image
    $broad_img1='<img src="' . $path."/".$web_image_folder."/".$image . '" />';
} else {
    // error, we can't find the image.
}

but i have now worked out i dont think my file unlink is working my code for this is this

$fileToRemove1 = 'image/thumbs/thumb_image1';
$exts = array('jpg', 'png', 'gif', 'jpeg');				

foreach($exts as $ext) {

   if (file_exists($fileToRemove1.'.'.$ext)) 
     {
        @chmod(0777, $fileToRemove1.'.'.$ext);
     }
     @unlink($fileToRemove1);
   }
   	
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: if file exists

  #12  
May 7th, 2008
remove @ and check if it throws any error. You are supposed to delete the file with the extension !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
robothy robothy is offline Offline
Light Poster

Re: if file exists

  #13  
May 7th, 2008
Kevin,

If you're sending the images out in an email, then yes you're right, the absolute links would be required. For the file exists, the relative links would suffice, or use the $_SERVER function (I think that is right).

A good way to test for the time being might be to produce a web page as opposed to an email. Get that working and then send it out as an email?

Just a thought.

Rob.
Reply With Quote  
Join Date: Feb 2008
Posts: 297
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #14  
May 7th, 2008
robothy

the page that is sent out in an email is a html page which has some dynamic elements added to it. the images are being sent now. the part which aint workin in the unlink side of it the files that are uploaded stay there unless i physically go on to the server and delete them myself.

Navman33

thank for the hint i will go and check that out now and see what is happening.
Reply With Quote  
Join Date: Feb 2008
Posts: 297
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #15  
May 7th, 2008
Nav33n

sorry bout the spelling mistake on your name i was just talking to someone about sat navs.

it has given me the error message

Warning: chmod(): No such file or directory in /home/acmeart/public_html/mercury/upload.php on line 28 Warning: unlink(image/thumbs/thumb_image1): No such file or directory in
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: if file exists

  #16  
May 7th, 2008
heh.. no probs ! As the warning itself says, chmod didn't find the file (and hence unlink didn't work). Check if the path to the file is correct for chmod and unlink!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Posts: 297
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #17  
May 7th, 2008
i have edited the code slightly and am getting a different error. it is now saying

Warning: unlink(thumb_image1): No such file or directory in /home/acmeart/public_html/mercury/upload.php on line 28

please correct me if i am wrong but to me it looks like it is trying to delete a file from the wrong place. the file i want removed is in the directory

image/thumbs

the warning looks to me if it is lokking for the image in the mercury/ directory on the server.
Reply With Quote  
Join Date: Feb 2008
Posts: 297
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #18  
May 7th, 2008
sorry about the stupid text above i didnt think it would come out like that the warring reads

Warning: unlink(thumb_image1): No such file or directory in /home/acmeart/public_html/mercury/upload.php on line 28
the directory the images are in is

images/thumbs
and my code now looks like

$path='image/thumbs/';
$fileToRemove1 = 'thumb_image1';
$exts = array('jpg', 'png', 'gif', 'jpeg');				

foreach($exts as $ext) {

   if (file_exists($path.'/'.$fileToRemove1.'.'.$ext)) 
     {
     unlink($fileToRemove1);
	 }
   	}
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
robothy robothy is offline Offline
Light Poster

Re: if file exists

  #19  
May 7th, 2008
Hey Kevin,

For the unlink, your code would need to read:

$path='image/thumbs/';
$fileToRemove1 = 'thumb_image1';
$exts = array('jpg', 'png', 'gif', 'jpeg');				

foreach($exts as $ext) {

if (file_exists($path.'/'.$fileToRemove1.'.'.$ext)) 
{
unlink($path.'/'.$fileToRemove1.'.'.$ext);  // you need to provide the full path and the extension
}
}
Reply With Quote  
Join Date: Feb 2008
Posts: 297
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #20  
May 7th, 2008
we must have got on to that at the same time i was just about to put this up when i seen your reply. thanks. i have got the code to work now i modified it so it now looks like this

<?php
$path='image/thumbs/';
$fileToRemove1 = 'thumb_image1';
$exts = array('jpg', 'png', 'gif', 'jpeg');				

foreach($exts as $ext) {

   if (file_exists($path.'/'.$fileToRemove1.'.'.$ext)) 
     {
     unlink($path.'/'.$fileToRemove1.'.'.$ext);
	 }
   	}
?>

i have moved the code on to its own page and used the include once function and it works fine it removes the file.

the problem now is the cache it is displaying old images instead of the new ones that have been uploaded. i found this code to stop the caching of the images but it has not seemed to work

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC