•
•
•
•
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
![]() |
i have got the images coming through with the email.
the code now looks like this
but i have now worked out i dont think my file unlink is working my code for this is 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);
}
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
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*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 6
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.
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.
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.
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.
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
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 •
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
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*
*PM asking for help will be ignored*
i have edited the code slightly and am getting a different error. it is now saying
: 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

the warning looks to me if it is lokking for the image in the
directory on the server.
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
the warning looks to me if it is lokking for the image in the
sorry about the stupid text above i didnt think it would come out like that the warring reads
the directory the images are in is
and my code now looks like
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);
}
}•
•
Join Date: Jan 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 6
Hey Kevin,
For the unlink, your code would need to read:
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
}
} 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
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
<?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">
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Ajax javascript test if image file exists (JavaScript / DHTML / AJAX)
- File I/O Help (C)
- ofstream - detect if file has been deleted between open and close (C++)
- Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!! (Java)
- file help (C++)
- to delete contents of a text file (Java)
- PHP file handling (PHP)
- Bridge.dll error please help me here is my hijackthis log file! (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: isp auto-detect
- Next Thread: Basic PHP Includes



Linear Mode