Jump to content

images being written over?


Michdd

Recommended Posts

I have a script that used to upload images, and I have something in it that is supposed to be changing then URL that it's uploaded to if that URL is already taken, however, it's not working, it's just overwriting the other image. Can anyone help me out?

 

The file:

 

<?php


   // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.JPG','.GIF','.BMP','.PNG'); // These will be the types of file that will pass the validation.
      $max_filesize = 2024288; // Maximum filesize in BYTES
      $upload_path = 'images/'; // The place the files will be uploaded to (currently a 'files' directory).
  $auth = "0";
  $auth = $_POST['auth'];
  $password = $_POST['password'];

   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

if($auth == "1") {   

$id = "0";
while(is_file($filename))
{
  $id++;
  $filename = $id.'_'.$filename;

}

   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes)){
      die('The file you attempted to upload is not allowed.');
}
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize){
      die('The file you attempted to upload is too large.');
}
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path)){
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
}
   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) {

   echo "Your submission was successfull<br />";
   echo $upload_path . $filename;

   
   } else {
   
   echo "There was a problem";



}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/129630-images-being-written-over/
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.