Markus 6,050
Recognized Expert Expert
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 1385 Atli 5,058
Recognized Expert Expert
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?
Markus 6,050
Recognized Expert Expert
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($qu ery) 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
Recognized Expert Expert
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.
Markus 6,050
Recognized Expert Expert
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.
Markus 6,050
Recognized Expert Expert
The mysql query is working fine: the url is deleted from the db
just the actual image isnt being deleted ¬_¬
Markus 6,050
Recognized Expert Expert
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 the images before
inserting them as BLOBs.
My problem is that (apart from being new to file stuff) my resize
function returns a Resource ID which of course is not the same as the
file handler that was passed to it, it's a reference to an image...
|
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" --> file "edit_text.php"
--> file "delete_img.php" (function 'unlink()' in it)
|
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 of the uploaded
file where i can delete the uploaded file if it is checked. Does anyone
have an idea of how to do this? Any help on this would be
appreciated. Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just...
|
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 of the
uploaded file where i can delete the uploaded file if it is checked.
Does anyone have an idea of how to do this? Any help on this would be
appreciated. Thanks.
|
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 doesnt exist
AppPath = Request.PhysicalApplicationPath + UploadDirectory;
if(!Directory.Exists(AppPath))
Directory.CreateDirectory(Request.PhysicalApplicationPath +
| |
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 not
supported. So I figured I'd just use System.IO functions (File.Delete)
to do it except that except for the OpenFileDialog component, none of
the functions can see the camera folder. If I access the pictures
using OFD then I get a file/path...
|
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 tab, I am loosing the file in the file
control. So, I am putting the file in a Session:
Session("PhotoFile") = filePhoto.PostedFile
When the user comes back to the tab with the File upload, an Image control
|
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
thumbnail).
3. Returns an array with a bool (false if the upload failed), and an
error message.
|
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 wondering if there;s anyone that can help me with code that writes the url of the uploaded image to the database and also the code of how to view the image.
Cheers
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |