I have terminated my mind and slang is a good way to organize my code, the work I do , But I need this simple to make it alright, I have $ id = $ _GET ["id"]; And that $ id = 352 ... now,
scenario :
The code below is where the user selects an image to upload Is:
$ query = mysql_query ("properties from selection WHERE id = '$ _GET [id]' ')); & lt; input type =" file "name =" image1 " Id = "image1" />
Php if (isset ($ query) & amp; amp; file_exists ("../uploads / properties /". Mysql_result ($ query, 0, "id ")." .jpg ")) {? & Gt; & lt; img height =" 100 "src =" ../ upload / properties / & lt; a target =" _ blank "href =" delete_script / deletepic.php? Id = & lt ;? Php echo mysql_result ($ query, 0, "id") ;? & Gt; "& gt; Delete Image & lt; / a & gt; & lt ;? php}? & Gt; Input Type =" File "name =" image2 "id =" image2 "/> & Lt ;? php if (isset ($ query) & amp; amp; and file_exists ("../uploads / properties /". Mysql_result ($ query, 0, "id"). "_ 2.jpg" )) {? & Gt; & lt; img height = "100" src = "../ upload / properties / & lt; a target =" _ blank "href =" delete_script / deletepic2.php? Id = & lt ;? Php echo mysql_result ($ query, 0, "id") ;? & Gt; "& gt; Delete image & lt; / a & gt; & lt ;? php}? & Gt;
If you click on img
Strong> If you take a look at src
, then the difference between the two is that an image will be uploaded as 352.jpg and the other 352_2.jpg . I have 10 images that the user can upload so that the images will be saved:
1: 352.jpg
2: 352_2.jpg
3: 352_3.jpg
4: 352_4.jpg
5: 352_5.jpg
6:
8: 352_8.jpg
now live For the part:
When this page is clicked, this code will run with the code deletepic.php
with the following code:
& lt ;? Php $ id = $ _GET ["id"]; $ file_path = "../uploads/properties/".$id."_".$i.".jpg"; ($ I = 2; $ i For & lt; 11; $ i ++) ($ file_path = "../uploads/properties/".$id."_".$i.".jpg"; $ File_path Return; } If (file_exists ($ file_path)) {resonant "file removed request"; } Else {resonance "no file was requested to be removed"; }? & Gt;
I know that the for loop is not working but basically I need a script to see the $ id. "_". $ I
and then if the file is located on the link that was clicked on the file it should be removed.
There is currently a solution to work for me, if I script 10 delete.php and run this block of code, every one, the only part I will convert it to script to work $ Img
by setting it every time $ img = "../../uploads/properties/" $ Id. ".jpg";
Next delete.php will be the value of $ img
$ img = "../../uploads/properties/" $ Id "_ 2.jpg";
etc.
At this time the code looks like this in delete.php :
There are some problems with your first code sample, for example SQL injection is to keep in mind that Mysql_ * functions have been deprecated; You should experiment instead, but this is not a question here ... Your delete.php script should look something like this:
& lt ;? Php $ id = $ _GET ['id']; $ ImageFolder = realpath ('../../ upload / properties'); $ ImagePath = $ imageFolder '/' $ id '.jpg'; If (file_exists ($ imagePath) & amp; amp; dirname (real path ($ imagePath)) == $ imageFolder {unlink ($ imagePath); Resonant "File Removed Request"; } Else {resonance "no file was requested to be removed"; }
Comments
Post a Comment