Jump to content

Recommended Posts

i have a few pictures that are generated from a database.

It goes into my database and returns urls

and then

 

echo "<a href='http://www.4tenproductions.com/ir/uploadedfiles2/" . $row['pic'] . "'><img style='border-width:4;border-style:double;border-color:black' src='http://www.4tenproductions.com/ir/uploadedfiles/resize_" . $row['pic'] . "'</a>";

 

so i have a bunch of clickable pictures.

 

I want a way to click a picture and it gets deleted.  i know how to delete using unlink, so basically i need to figure out how to return the name of the file clicked on...  Idk if there is a function in PHP for that, or if javascript is required or what, but any help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/63269-unlink-find-the-url-of-clicked-image/
Share on other sites

will it be able to delete from the database too?  it needs to delete 3 different places.

 

//Delete from server thumbnail

$file1 = "http://www.4tenproductions.com/ir/uploadedfiles/resize_" . $filename;

unlink($file1);

//Delete from server picture

$file2 = "http://www.4tenproductions.com/ir/uploadedfiles2/" . $filename;

unlink($file2);

//Delete from database

$sql2 = mysql_query("DELETE FROM pics WHERE pic ='$file2'")

 

 

yea that got me the right name good.

 

but is unlink the way to delete a file from the server?  because its not working...

 

<?PHP

$filename = $_REQUEST["image"];

//Delete from server

$file1 = "http://www.4tenproductions.com/ir/uploadedfiles/resize_" . $filename;

unlink($file1);

$file2 = "http://www.4tenproductions.com/ir/uploadedfiles2/" . $filename;

unlink($file2);

//Delete from database

$sql2 = mysql_query("DELETE FROM pics WHERE pic ='$file2'");

echo "Image Deleted";

?>

 

it says image delete, but its not deleting anything...from any of the 3 places

row['pic'] is coming from a select query.

$sql = mysql_query("SELECT pic FROM pics WHERE user='$table'");

 

you said that i need to unlink($filename)

 

but how does it know where that file is located on my server?  i read from a site that its supposed to be the url that is getting unlinked i think im using it wrong.

 

i also have an odd query which im not sure will work, but its this

 

$sql2 = mysql_query("DELETE FROM pics WHERE pic='$filename' and user='$table'");

 

i dont know if i can use and in there.  the other option is to add another row in there to keep a unique number.  but id rather use and if i can.  i have like 8 pictures all with the user name JohnRobberts.  so i cant say delete where user=johnrobberts, and i cant say just delete where pic ="url" because some other user might have the same url, so i need to specify both, and id rather not add that 3rd row if i have to.

 

i still think im using unlink wrong, but it cant work with just $filename, because it wont know where to find it..

ok so making progress

 

i added the 3rd column, it only took 3 seconds... lol, and i 4got to connect to the database. so now thats working, but it still wont delete from 2 spots on the server.

 

<?PHP

$con = mysql_connect("xxxx","xxxx","xxxx");

mysql_select_db("update1", $con);

$filename = $_REQUEST["image"];

$table = $_REQUEST["table"];

$num = $_REQUEST["num"];

echo $filename;

echo $table;

echo $num;

//Delete from server  DOESNT WORK

$file1 = "/ir/uploadedfiles/resize_" . $filename;

unlink($file1);

$file2 = "/ir/uploadedfiles2/" . $filename;

unlink($file2);

//Delete from database WORKS

$sql2 = mysql_query("DELETE FROM pics WHERE num='$num'");

echo "Image Deleted";

 

?>

 

Well, whoever told you unlink() needed to be the url was somewhat right.  It needs to be the path to the file from the current working directory.  So, if it's up 1 directory and then in the images folder, it would be

 

$file = '../images/' . $filename;
unlink($file);

 

Am I making any sense?

 

On an unrelated note, you should be careful using $_REQUEST, as it's rather susceptible to attacks (especially if you're not doing any security checks on the input)

 

If it still doesn't work, perhaps add an echo $file1 prior to the unlink, or even change it to

unlink($file1) or die("Unable to delete: $file1");

well the php file is located at 4tenproductions.com

the files i want to delete are located at 4tenproductions.com/ir/uploadedfiles2

and 4tenproductions.com/ir/uploadedfiles

 

so would it be

$file1 = "/ir/uploadedfiles/resize_" . $filename;

 

because thats what im using, and its not working.  just to clarify:

php file is at:  http://www.4tenproductions.com/jrdelpic2.php

file1 is at:  http://www.4tenproductions.com/ir/uploadedfiles/

file2 is at:  http://www.4tenproductions.com/ir/uploadedfiles2/

 

and instead of request, what is safer GET or POST?  because a lot of my form methods are POST so thats fine, but a lot of variables are passed thru the URL too so id have to use GET but i heard GET is less secure than POST...

 

 

You should use whatever form is being used to pass the variable.  If you're passing it via link, the only option is GET.  It's less secure as it's susceptible to tampering from people, but it's also the only option.  However, REQUEST also calls from cookies, so you just need to be careful.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.