Thumbnail - Remove

See all posts Reply

Thumbnail - Remove new!
by David, 13 years, 11 months ago
When uploading a photo, it creates a duplicate with the extension _1 is there any way to stop it creating two?

An example would be:

image.jpg
image_1.jpg

I like it to stop creating image_1.jpg.

Thank you in advance.Reply
Re: Thumbnail - Remove new!
by David, 13 years, 11 months ago
This is the code I'm using, it uploads the 20 images to both server and file name to database, however on the server its creating 40 images instead of 20. They all have an extra one with same dimensions and size just with _1 added.

Any help would be great...

error_reporting(E_ALL);

$host="localhost"; // Host name
$username="xxxxxx"; // Mysql username
$password="xxxxxx "; // Mysql password
$db_name="xxxxxx"; // Database name
$tbl_name="xxxxxx"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("xxxxxx")or die("cannot select DB");

// we first include the upload class, as we will need it here to deal with the uploaded file
// create an array to hold your filnames
include('class.upload.php');
$images = array();

$files = array();
foreach ($_FILES['my_field'] as $k => $l) {
 foreach ($l as $i => $v) {
 if (!array_key_exists($i, $files))
   $files[$i] = array();
   $files[$i][$k] = $v;
 }
}      
foreach ($files as $file) {
  $handle = new Upload($file);
  if ($handle->uploaded) {
    $handle->Process("./test/");
    if ($handle->processed) {
      // add the filename to the array
      $images[] = $handle->file_dst_name;
    }
  }
  else {
    $images[] = ("blank.jpg");
    }

  unset($handle);
}

// you can insert the filenames in your database here, 
// from the array in which you stocked them
// but you will need to do some error checking, in case of the upload didn't work
$sql = "INSERT INTO photos3 (my_field1, my_field2,my_field3, my_field4, my_field5, my_field6, my_field7, my_field8, my_field9, my_field10, my_field11, my_field12, my_field13, my_field14, my_field15, my_field16, my_field17, my_field18, my_field19, my_field20) ";
$sql .= "VALUES ('".mysql_real_escape_string($images[0])."', '".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."', '".mysql_real_escape_string($images[5])."', '".mysql_real_escape_string($images[6])."', '".mysql_real_escape_string($images[7])."', '".mysql_real_escape_string($images[8])."', '".mysql_real_escape_string($images[9])."', '".mysql_real_escape_string($images[10])."', '".mysql_real_escape_string($images[11])."', '".mysql_real_escape_string($images[12])."', '".mysql_real_escape_string($images[13])."', '".mysql_real_escape_string($images[14])."', '".mysql_real_escape_string($images[15])."', '".mysql_real_escape_string($images[16])."', '".mysql_real_escape_string($images[17])."', '".mysql_real_escape_string($images[18])."', '".mysql_real_escape_string($images[19])."')";
$x = mysql_query($sql);

// retrieve eventual CLI parameters
$cli = (isset($argc) && $argc > 1);
if ($cli) {
    if (isset($argv[1])) $_GET['file'] = $argv[1];
    if (isset($argv[2])) $_GET['dir'] = $argv[2];
    if (isset($argv[3])) $_GET['pics'] = $argv[3];
}

// set variables
$dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : 'test');
$dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);
Reply
Re: Thumbnail - Remove new!
by David, 13 years, 10 months ago
Issue resolved, it was a personal error on the form I was sending it through!

Thanks!
DavidReply