Jump to content

$unlink'ing photos


graham23s

Recommended Posts

Hi Guys,

 

what i'm trying to do here is unlink(delete) the previously uploaded photo by the user, before the new one is uploaded, but i'm having trouble with the unlink bit

 

here the code:

 

 

<?php    
  $photo1 = $_FILES["image"]["name"];
  $username = mysql_escape_string($_POST["username"]);
  $max_image_size = 512000; 
  $allowed = array("image/gif","image/jpg","image/png","image/jpeg");
  $max_image_width = 500;
  $max_image_height = 450;
  $random_number = rand(0000,9999);
  
  // The renamed photo...////////////////////////////////////////////////////////////////
  $renamed_photo = $random_number.$_FILES["image"]["name"];   
  
  // Check there wasn't a blank submission...////////////////////////////////////////////
  if(empty($_FILES["image"]["name"])) {
  
       echo "<p>Sorry, But No File Was Selected, Please Go Back And Try Again.</p>";
       exit;  
  }
  
  // Validation for Image...
  if ($_FILES["image"]["size"] > $max_image_size) {
  
   echo "<p>Sorry <b>$username</b> That Image Is Bigger Than The Allowed Size Of 3mb Please <a href=\"java script: history.go(-1)\">Go Back</a></p>";
   exit;
   
  }
  
  #####################################################################
  // Validate image dimensions...////////////////////////////////////////////////////////
  $dim = getimagesize($_FILES["image"]["tmp_name"]);

  if($dim[0] >= $max_image_width || $dim[1] >= $max_image_height) {
  
    echo "<p>Sorry, That Image Isn't Within The Current Upload Dimensions Please Go Back And Upload Another!</p>";
    exit;
    
  }  
  // Validate image types.../////////////////////////////////////////////////////////////
  if (!in_array($_FILES["image"]["type"], $allowed)) {
  
    echo "<p>Sorry, That File Isn't One Of The Allowed File Types Only <b>.gif .jpg & .png</b> Are Allowed.</p>";
    exit;
    
  }  
  #####################################################################
  
  $uploadpath = "uploads/"; // <- Upload folder...
  $uploadpath = $uploadpath.$renamed_photo;

  #####################################################################  
  if (!move_uploaded_file($_FILES["image"]["tmp_name"], $uploadpath)) 
  
     die("<p>Sorry, There Was An Error Uploading Your Image!");
     echo("<p><br />The Image (<b><font color=\"red\">" .$_FILES["image"]["name"]. "</b></font>) Has Been Uploaded Successfully! <a href=\"my_account.php\">Back To My Account</a><br />");
     
    
  // Create our query.../////////////////////////////////////////////////////////////////
  $sql = "UPDATE membership SET photo1='$renamed_photo' WHERE username='$username'";

  // Run our query...////////////////////////////////////////////////////////////////////
  $rs = mysql_query($sql, $conn) or die(mysql_error());
?>

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/49166-unlinking-photos/
Share on other sites

Hi Mate,

 

it's not really 1 particular image file , it's basically whatever the user uploads as a pic, heres my form code:

 

<form action="upload_photo_done.php" method="POST" enctype="multipart/form-data">
<tr>
<td bgcolor="#E2E2E2">Upload Location:</td><td bgcolor="#E2E2E2" align="left"><input type="file" name="image" size="40"></></td>
<tr>
<td bgcolor="#E2E2E2">Current Uploaded Photo:</td><td bgcolor="#E2E2E2"><?php 
    if($photo != 0) { 
    
     echo "<img src='uploads/no_pic.jpg' />"; 
     
       } else { 
    
     echo "<img src='uploads/$photo1' border='0' />"; 
     }
?></td><td><a href="">Delete</a></td>
<tr>
<td bgcolor="#E2E2E2"> </td><td bgcolor="#E2E2E2"><input type="submit" name="submit" value="Upload Main Photo!"></td>
<input type="hidden" name="username" value="<?php echo $username; ?>" >
<input type="hidden" name="MAX_FILE_SIZE" value="MAX_FILE_SIZE" />
</tr>
</form>

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/49166-unlinking-photos/#findComment-240995
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.