emediastudios
-
Posts
418 -
Joined
-
Last visited
Posts posted by emediastudios
-
-
yes it opens a property deleted.php file. thanks il give it a go
-
If i change it to post photo1 i have heaps of code i have to alter, my database along with others.
-
Thanks for your help but still stuck
Could you past that code in my code below and ill see if it works.
Heres my code
if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = "../images/". $_POST['photo']; $myFile2 = "../images/". $_POST['photo2']; $myFile3 = "../images/". $_POST['photo3']; $myFile4 = "../images/". $_POST['photo4']; $myFile5 = "../images/". $_POST['photo5']; $myFile6 = "../images/". $_POST['photo6']; $myFile7 = "../images/". $_POST['photo7']; $myFile8 = "../images/". $_POST['photo8']; $myFile9 = "../images/". $_POST['photo9']; if (!empty($_POST['photo'])) { unlink($myFile); } else { echo ""; } if (!empty($_POST['photo2'])) { unlink($myFile2); } else { echo ""; } if (!empty($_POST['photo3'])) { unlink($myFile3); } else { echo ""; } if (!empty($_POST['photo4'])) { unlink($myFile4); } else { echo ""; } if (!empty($_POST['photo5'])) { unlink($myFile5); } else { echo ""; } if (!empty($_POST['photo6'])) { unlink($myFile6); } else { echo ""; } if (!empty($_POST['photo7'])) { unlink($myFile7); } else { echo ""; } if (!empty($_POST['photo8'])) { unlink($myFile8); } else { echo ""; } if (!empty($_POST['photo9'])) { unlink($myFile9); } else { echo ""; } } header("Location: $deleteGoTo"); }
-
I use this code
if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = "../images/". $_POST['photo']; $myFile2 = "../images/". $_POST['photo2']; $myFile3 = "../images/". $_POST['photo3']; $myFile4 = "../images/". $_POST['photo4']; $myFile5 = "../images/". $_POST['photo5']; $myFile6 = "../images/". $_POST['photo6']; $myFile7 = "../images/". $_POST['photo7']; $myFile8 = "../images/". $_POST['photo8']; $myFile9 = "../images/". $_POST['photo9']; for($i=0;$i<count($_POST['photo']);$i++) { if (!empty($_POST['photo'][$i])) unlink($myFile[$i]); } } header(sprintf("Location: %s", $deleteGoTo)); }
and get this error
Warning: unlink(.) [function.unlink]: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_delete.php on line 117
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_delete.php:117) in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_delete.php on line 122
-
Hi there
I have this code
if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = "../images/". $_POST['photo']; $myFile2 = "../images/". $_POST['photo2']; $myFile3 = "../images/". $_POST['photo3']; $myFile4 = "../images/". $_POST['photo4']; $myFile5 = "../images/". $_POST['photo5']; $myFile6 = "../images/". $_POST['photo6']; $myFile7 = "../images/". $_POST['photo7']; $myFile8 = "../images/". $_POST['photo8']; $myFile9 = "../images/". $_POST['photo9']; if (!empty($_POST['photo'])) { unlink($myFile); } else { echo ""; } if (!empty($_POST['photo2'])) { unlink($myFile2); } else { echo ""; } if (!empty($_POST['photo3'])) { unlink($myFile3); } else { echo ""; } if (!empty($_POST['photo4'])) { unlink($myFile4); } else { echo ""; } if (!empty($_POST['photo5'])) { unlink($myFile5); } else { echo ""; } if (!empty($_POST['photo6'])) { unlink($myFile6); } else { echo ""; } if (!empty($_POST['photo7'])) { unlink($myFile7); } else { echo ""; } if (!empty($_POST['photo8'])) { unlink($myFile8); } else { echo ""; } if (!empty($_POST['photo9'])) { unlink($myFile9); } else { echo ""; } } header(sprintf("Location: %s", $deleteGoTo)); }
I was told to use these codes and i had it working, but i did something and cant get it to work again
<?php for($i=0;$i<count($_POST['photo'];$i++) { if (!empty($_POST['photo'][$i]) unlink($myFile[$i]); } ?>
and this one
<?php $myFile = array(); for ($i=1;$i<count($_POST['photo']);$i++) $myFile[$i] = '../images/' . $_POST['photo'][$i]; ?>
How can i replace my code with this much more simplified code?
Thanks all
-
I got it thanks champ, your the best
-
Thanks for your help, really appreciate it, it deletes the images still and im stoked bout that, just the error i need to fix, thanks again
-
Now this error
Parse error: syntax error, unexpected '[' in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_deleted.php on line 115
if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = "../images/". $_POST['photo']; $myFile2 = "../images/". $_POST['photo2']; $myFile3 = "../images/". $_POST['photo3']; $myFile4 = "../images/". $_POST['photo4']; $myFile5 = "../images/". $_POST['photo5']; $myFile6 = "../images/". $_POST['photo6']; $myFile7 = "../images/". $_POST['photo7']; $myFile8 = "../images/". $_POST['photo8']; $myFile9 = "../images/". $_POST['photo9']; } for($i=0;$i<count($_POST['photo']);$i++) { if (!empty($_POST['photo'])[$i]) /////////This is line 115//////////// unlink($myFile[$i]); }
-
if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = "../images/". $_POST['photo']; $myFile2 = "../images/". $_POST['photo2']; $myFile3 = "../images/". $_POST['photo3']; $myFile4 = "../images/". $_POST['photo4']; $myFile5 = "../images/". $_POST['photo5']; $myFile6 = "../images/". $_POST['photo6']; $myFile7 = "../images/". $_POST['photo7']; $myFile8 = "../images/". $_POST['photo8']; $myFile9 = "../images/". $_POST['photo9']; } for($i=0;$i<count($_POST['photo']);$i++) { if (!empty($_POST['photo'][$i]) unlink($myFile[$i]); } header(sprintf("Location: %s", $deleteGoTo)); }
-
Thanks for your help ken, i changed it but now this error
Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_deleted.php on line 116
The line is this one
unlink($myFile[$i]);
-
Can i simplify this code too.
$myFile = "../images/". $_POST['photo']; $myFile2 = "../images/". $_POST['photo2']; $myFile3 = "../images/". $_POST['photo3']; $myFile4 = "../images/". $_POST['photo4']; $myFile5 = "../images/". $_POST['photo5']; $myFile6 = "../images/". $_POST['photo6']; $myFile7 = "../images/". $_POST['photo7']; $myFile8 = "../images/". $_POST['photo8']; $myFile9 = "../images/". $_POST['photo9'];
-
The line of code is
for($i=0;$i<count($_POST['photo'];$i++) {
-
Used your code and it works, deletes the images ( photos ), but i get this error,
Parse error: syntax error, unexpected ';' in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_deleted.php on line 114
-
Could there be a simple way, less code and do the same task?
This is the code i have
if (!empty($_POST['photo'])) { unlink($myFile); } else { echo ""; } if (!empty($_POST['photo2'])) { unlink($myFile2); } else { echo ""; } if (!empty($_POST['photo3'])) { unlink($myFile3); } else { echo ""; } if (!empty($_POST['photo4'])) { unlink($myFile4); } else { echo ""; } if (!empty($_POST['photo5'])) { unlink($myFile5); } else { echo ""; } if (!empty($_POST['photo6'])) { unlink($myFile6); } else { echo ""; } if (!empty($_POST['photo7'])) { unlink($myFile7); } else { echo ""; } if (!empty($_POST['photo8'])) { unlink($myFile8); } else { echo ""; } if (!empty($_POST['photo9'])) { unlink($myFile9); } else { echo ""; }
-
If i had more images that one i could just duplicate the code like
$myFile2 = "../images/". $_POST['photo2']; unlink($myFile2);
But if i dont have a photo2 i get this error.
Warning: unlink(../images/) [function.unlink]: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\property_delete.php on line 106
Can i use a if empty statement somehow?
-
Thanks Champ
-
How would i add code to this so that it reads it as ../images/$_POST['photo'];
I have
$myFile =$_POST['photo']; unlink($myFile);
This works if the file is in the directory this file resides but it doesnt, it is is my images folder ../images.
-
Thanks, still a bigginer so i dont know where to start with your code.
I have this code and when i execute the code it tries t delete a file called "testfile.txt, doesnt ork though as that file doesnt exsist.
How would i change this so that it echos the $row_Recordset1['photo'] instead of testfile.txt?
if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = "testFile.txt"; unlink($myFile);
-
If i add a recordset and this code
<?php $file_delete = "../images/<?php echo $row_Recordset1['photo']; ?>"; if (unlink($file_delete)) { echo "The file was deleted successfully.", "\n"; } else { echo "The specified file could not be deleted. Please try again.", "\n"; } ?>
I get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\deletfiles.php on line 42
-
I want to add a code similar to this i guess
<?php $file_delete = "../images/<?php echo $row_Recordset1['photo']; ?>"; /////////-------------- dont think this is right-------------///////// if (unlink($file_delete)) { echo "The file was deleted successfully.", "\n"; } else { echo "The specified file could not be deleted. Please try again.", "\n"; } ?>
-
I use the dreamweaver generated code to delete a record, how would i add some code to it to delete the files (images) stored in my../images folder, that are linked to the record being deleted, there field names are photo1, photo2, ect..... and there image names are stored in the database
Here is the dreamweaver code.
<?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if ((isset($_GET['name'])) && ($_GET['name'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE name=%s", GetSQLValueString($_GET['name'], "text")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } if ((isset($_POST['name'])) && ($_POST['name'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE name=%s", GetSQLValueString($_POST['name'], "text")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } mysql_select_db($database_gcproperty, $gcproperty); $query_Recordset1 = "SELECT * FROM employees"; $Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?>
-
is your database the same name on your server?
-
There seems to be an error in my code, Can someone spot it?
Thanks
<?php if (!empty($row_Recordset1['photo'])) { echo <img src="../images/<?php echo $row_Recordset1['photo']; ?>" alt="image" width="150" /> else { echo ""; } ?><br />
-
I have a code that uploads images along with some info into a directory and database, this all works fine.
I can delete the record but the images relevent to that record continue to exsist in my images directory.
How would i set up a php code to delete a file in ../images when the record of its name is stored in a column in my database.
Here is my delete record code.
The image records in my database are in a columns named photo1, photo2, etc..
<?php require_once('../Connections/gcproperty.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = ""; $MM_donotCheckaccess = "true"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "restricted.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if ((isset($_POST['name'])) && ($_POST['name'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE name=%s", GetSQLValueString($_POST['name'], "text")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } mysql_select_db($database_gcproperty, $gcproperty); $query_Recordset1 = "SELECT * FROM employees"; $Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration Panel</title> <style type="text/css"> <!-- .style1 {color: #000000} body { background-color: #000000; } .style2 { color: #FFFFFF; font-size: 10px; } --> </style> <link href="../css/admin.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style3 {font-size: 10px} .style4 {font-size: 16px} .style5 { color: #FFFFFF; font-size: 10px; } .style5 {color: #FFFFFF} --> </style> <link href="../css/main.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style7 {font-size: 18px} --> </style> </head> <body> <div id="container"><table width="780" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="8"><img src="../images/admin-header.jpg" alt="GC Propery" width="780" height="223" /></td> </tr> <tr> <td width="132" height="24" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="edit_privacy.php" target="_self">Terms / Privacy</a></div></td> <td width="91" background="../images/navbar.jpg" class="name"><div align="center" class="admin"> <a href="investour.php" target="_self">Investour</a></div></td> <td width="96" background="../images/navbar.jpg" class="name"><div align="center" class="admin"> <a href="property_add.php" target="_self">Property</a></div></td> <td width="99" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="news.php" target="_self">News</a></div></td> <td width="81" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="email.php" target="_self">email</a></div></td> <td width="108" background="../images/navbar.jpg" class="name"><div align="center" class="admin"> <a href="links.php" target="_self">Links</a></div></td> <td width="96" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="main.php" target="_self">Main Content</a></div></td> <td width="77" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="logout.php" target="_self" class="admin">Logout</a></div></td> </tr> <tr> <td height="2" colspan="8" background="../images/bar.jpg" class="admin"> </td> </tr> <tr> <td colspan="8" class="admin"><div align="left"> <blockquote> <p class="style2"><br /> <u><span class="style4">Edit GCProperty.</span></u><br /> <br /> <span class="style4"><a href="property_add.php" target="_self">Click here to Add Property <br /> </a></span></p> <?php if ($totalRows_Recordset1 == 0) { // Show if recordset empty ?> <table width="600" border="0" align="center"> <tr> <td><div align="center"><span class="name">There are no properties to delete</span></div></td> </tr> </table> <?php } // Show if recordset empty ?> <?php do { ?> <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <form id="form1" name="form1" method="post" action=""> <table width="507" border="0" align="center" bgcolor="#333333"> <tr> <td colspan="3" bgcolor="#999999"><span class="style7">Delete Property</span></td> </tr> <tr> <td colspan="3">Delete a property from the GCPRoperty Database <hr /></td> </tr> <tr> <td width="251"><div align="right">Name:</div></td> <td width="26"> </td> <td width="216"><input name="name" type="text" id="name" value="<?php echo $row_Recordset1['name']; ?>" /></td> </tr> <tr> <td><div align="right">Suburb:</div></td> <td> </td> <td><input name = "suburb" type="text" id="suburb" value="<?php echo $row_Recordset1['suburb']; ?>" /></td> </tr> <tr> <td><div align="right">Price: </div></td> <td> </td> <td><input name = "price" type="text" id="price" value="<?php echo $row_Recordset1['price']; ?>" /></td> </tr> <tr> <td><div align="right">Photo:</div></td> <td> </td> <td><img src="../images/<?php echo $row_Recordset1['photo']; ?>" alt="image" width="150" /><br /> <label> <input name="photo" type="text" id="photo" value="<?php echo $row_Recordset1['photo']; ?>" /> </label></td> </tr> <tr> <td><div align="right">Photo2:</div></td> <td> </td> <td><img src="../images/<?php echo $row_Recordset1['photo2']; ?>" alt="image" width="150" /><br /> <label> <input name="photo2" type="text" id="photo2" value="<?php echo $row_Recordset1['photo2']; ?>" /> </label></td> </tr> <tr> <td><div align="right">Photo3:</div></td> <td> </td> <td><img src="../images/<?php echo $row_Recordset1['photo3']; ?>" alt="image" width="150" /><br /> <label> <input name="photo3" type="text" id="photo3" value="<?php echo $row_Recordset1['photo3']; ?>" /> </label></td> </tr> <tr> <td><div align="right">Text</div></td> <td> </td> <td><label> <textarea name="content" cols="40" rows="10" id="content"><?php echo $row_Recordset1['content']; ?></textarea> </label></td> </tr> <tr> <td> </td> <td> </td> <td><input name="Submit" type="submit" value="Delete" /></td> </tr> </table> <br /> </form> <?php } // Show if recordset not empty ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> <p align="center" class="style2"> </p> </blockquote> </div></td> </tr> <tr> <td colspan="8" class="admin"><div align="center"><br /> </div></td> </tr> <tr> <td colspan="8" class="admin"><br /> <br /></td> </tr> <tr> <td colspan="5"> </td> <td> </td> <td> </td> </tr> </table> <div align="center"><br /> <br /> </div> </body> </html> <?php mysql_free_result($Recordset1); ?>
[SOLVED] Simplifiy code (array)
in PHP Coding Help
Posted
I went to the trouble of renaming photo to photo1 in all my code and all my pages and used your code.
It works.
Thanks so much