Page 1 of 1

File Rename Not working

Posted: Mon Feb 16, 2009 8:02 am
by tyanque
I'm making a script which renames a image when it is uploaded to use the name of the album it has been uploaded to as a prefix and +1 of what the latest ID is e.g. If the latest ID is 1, it renames the image to 2, at the moment this is not working it is just calling every image 0.jpg. Here is my code.

Code: Select all

$imageNewNamePrefix = $_POST['album'];
$imageNewNameID = mysql_query("SELECT `images`.`photoID` FROM `images` ORDER BY `images`.`photoID` DESC LIMIT 1");
$datarow = mysql_fetch_assoc($imageNewNameID);
$number = $datarow['photoID']+1;
$imageNewNameJoined = $imageNewNamePrefix&$number;
$image_name=$imageNewNameJoined.'.'.$extension; 
Thanks in advance for any help :)

Re: File Rename Not working

Posted: Mon Feb 16, 2009 8:10 am
by VladSun
I would advice you to use
[sql]SELECT MAX(`images`.`photoID`) AS lastPhotoID FROM `images`[/sql]
instead of ORDER/LIMIT query
Also, take a look what you have in $datarow by using print_r($datarow)

And finally - change this line

Code: Select all

$imageNewNameJoined = $imageNewNamePrefix&$number;
to

Code: Select all

$imageNewNameJoined = $imageNewNamePrefix.$number;
& is not the concatenation operator in PHP :)

Re: File Rename Not working

Posted: Mon Feb 16, 2009 8:12 am
by susrisha

Code: Select all

 
[color=#FF0000]$imageNewNameJoined = $imageNewNamePrefix&$number;[/color]
$imageNewNameJoined = $imageNewNamePrefix.$number;