File Rename Not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tyanque
Forum Newbie
Posts: 2
Joined: Mon Feb 16, 2009 7:53 am

File Rename Not working

Post 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 :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: File Rename Not working

Post 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 :)
Last edited by VladSun on Mon Feb 16, 2009 8:12 am, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: File Rename Not working

Post by susrisha »

Code: Select all

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