Jump to content

delete from folder


chris_s_22

Recommended Posts

This is the code i use to upload a photo to a folder and put file name in database.

 

However if someone was to re use the form to change photo id like it so that the old one was deleted

How do i do this

 

<?php 
include 'Connect.php';

if(!isset($_POST[submit])) // checks that the data being recieved came from a POST variable named 'submit'  
{
   	 // if error reshow the form You cannot access this page directly.
   	 include 'index.php';
   	 exit;
}
else
{
if ((($_FILES["photo"]["type"] == "image/gif") 
|| ($_FILES["photo"]["type"] == "image/jpeg") 
|| ($_FILES["photo"]["type"] == "image/pjpeg"))
&& ($_FILES["photo"]["size"] < 51000))
{

	$ext = findexts ($_FILES['photo']['name']) ; //This applies the function to our file 
	$ran = rand () ;//This line assigns a random number to a variable.
	$ran2 = $ran."."; //adds a . on the end of $ran 
	$target = "images/"; //This is the directory where images will be saved
	$pic = $ran2.$ext;//This gets information from the form that has since been randomised and checked
	$target = $target . $ran2.$ext;//This combines the directory, the random file name, and the extension
	//If everything is ok we try to upload it 

	//Writes the information to the database 
	mysql_query("UPDATE members SET photo = '$pic' WHERE username = '$username'") ;
	if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
	{
	header('Location: index.php');   
	} 
	else 
	{ 
	echo "Sorry, there was a problem uploading your file."; 
	}  
}
else
{
echo "Invalid file";
}
}
?> 

Link to comment
Share on other sites

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.