I have the following code the create random images with unique names to it, the script supposed to name the image files with a combination of the STOCK and a incremental number, for example:
Stock Number = 200
Will create 3 images like 200-1.jpg, 200-2.jpg and 200-3.jpg
My problem is this code is creating only the first file 200-1.jpg when I upload the 2nd file still it is naming the 1st.
Please help me to fix this code so that everything I execute this the image numbering should be incremental
PHP Code:
if($image && isset($_REQUEST['itemcode'])) {
$link = mysql_connect($dbhost, $dbuser, $dbpass);
$result = mysql_db_query($dbname, "select stock from $dbvin where itemcode='". $itemcode ."'", $link);
if ( 0 < mysql_num_rows($result) ) {
$data = mysql_fetch_assoc($result);
$i = 1;
$error = false;
while ( false == $error ) {
echo $i . '<br>';
if ( !file_exists('./temp/' . $data['stock'] . '-' . $i . '.jpg') ) {
echo 'exists: ' . './temp/' . $data['stock'] . '-' . $i . '.jpg<br>';
$i++;
break;
}
$i++;
}
$icode = $data['stock'] . '-' . $i;
|