Now, i know it's possible to delete files using 'unlink'.
But, i tried this against a jpg file, to no avail.
I have done some research but have been unable to find anything to approach this with.
Sorry in advance.
And thanks... in advance :D
6 1370 Atli 5,058
Expert 4TB
Hi Markus.
The unlink() function can delete all files on your server it has access to. That is to say, the user running the PHP process must have write permission on the file to delete it.
Could you show us your code and any errors you were getting?
Yeh sure!
I used the 'unlink' on an image BUT i checked and the image was still there..
Here's the code :)
[php]
<?php
$file = $_GET['file']; //file to delete
include("../connectionstuff"); //config for mysql
include("../connectionstuff"); //open database mysql
$query = "DELETE FROM `ma_pics` WHERE `url_short` = '$file'"; /*delete from database! If not done, images will try to appear in the recently uploaded section! */
mysql_query($query) or die ("Error encountered: ".mysql_error.""); // query it.
$fh = fopen($file, 'w') or die("can't open file"); // open file
fclose($fh); // and close so no other part is using it!
unlink($file) or die("error!"); //this is the deleting part :D
echo "<p>Image '".$file."': deleted.</p>"; //on success => let user know of delete
?>
[/php]
I don't get any errors, just that the file is never ACTUALLY deleted.
Thanks :)
Atli 5,058
Expert 4TB
Ok, I see no major problem with that code. If the $_GET super-global contains a valid file path then that file should be deleted. (Assuming the database query doesn't fail and stop the code first.)
What does the file path look like? Are you sure it points to a the file?
A few notes about the code.
You include the "../connectionstuff" twice. Dunno if thats on purpose or not but, anyways.
Also, assuming you use the fopen() and fclose() functions there on the $file path to check if it actually exists, you could try the file_exists() function or even the is_writable() function to see if it exists and can be deleted.
Ok, I see no major problem with that code. If the $_GET super-global contains a valid file path then that file should be deleted. (Assuming the database query doesn't fail and stop the code first.)
What does the file path look like? Are you sure it points to a the file?
A few notes about the code.
You include the "../connectionstuff" twice. Dunno if thats on purpose or not but, anyways.
Also, assuming you use the fopen() and fclose() functions there on the $file path to check if it actually exists, you could try the file_exists() function or even the is_writable() function to see if it exists and can be deleted.
Thanks for the input!
the connection stuff was actually two seperate things but i removed the actual names of the files :)
I'll have a play around with stuff.
I've hit a new problem though with creating directories, but thats for another time, i think.
Thanks a bunch.
The mysql query is working fine: the url is deleted from the db
just the actual image isnt being deleted ¬_¬
Would this(script), by any chance, have to be in the same directory as the file being deleted? SOLVED!!!! Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mat |
last post by:
Hi,
I have a system that uploads images as BLOBs in a database. I also
have a function that I use to resize uploaded images before saving as
files. I would like to combine these two by resising...
|
by: phpfrizzle |
last post by:
Hi there,
I have built a CMS, and in one part you have to be able to
delete images. Structure like this:
_root --> folder "img" --> file "1.jpg"
--> file "2.jpg"
--> folder "CMS" ...
|
by: Eddie Tan |
last post by:
Hi everyone hope you guys can help me out on this. I'm working on an
upload page where it has the file name, file size, and type of the file
that is uploaded. I want to add a checkbox next to each...
|
by: ed |
last post by:
Hi everyone hope you guys can help me out on this. I'm working on an
upload page where it has the file name, file size, and type of the
file that is uploaded. I want to add a checkbox next to each...
|
by: troy |
last post by:
Hello,
I have the following code that run in the page_load section:
private void Page_Load(object sender, System.EventArgs e)
{
/// Create uploads folder in the Virtua; directory if one...
|
by: greyseal |
last post by:
I've gone around and around this thing for the last day or so.
Using WIA, I can take and copy images from my Nikon D2H. However, when
I attempt to delete the image I find that that capability is...
|
by: Satish Appasani |
last post by:
Hi:
I have a ASP.NET form with Web layout which I've achieved using panels. In
one of the tab I have a File control to upload Images. When I put a file in
the file control and move to another...
|
by: IkBenHet |
last post by:
Hello,
I use this script to upload image files to a folder on a IIS6 server:
******************* START UPLOAD.ASPX FILE **********************
<%@ Page Language="VB" Debug="true" %>
|
by: ctiggerf |
last post by:
I was hopeing someone could help me out here. Been stumped on this
one all day.
This function
1. Checks uploaded files.
2. Creates two resized images from each (a full size, and a...
|
by: shafshaa |
last post by:
Hi i am working on a website, something sort of similar to myspace idea, users can upload images, the images are uploaded to a folder on the server, i have managed to get that bit ok, i am just...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |