anf.etienne Posted March 3, 2009 Share Posted March 3, 2009 noob question. how can i start with the number 1 and then get php to add 1 for each image name? so i start wit 1.jpg and php adds 1 to get 2.jpg and then the same for the rest....i really am a noob wit php Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted March 3, 2009 Share Posted March 3, 2009 I think you would need to describe a bit more of what you are trying to do... Your question is rather vague. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 3, 2009 Share Posted March 3, 2009 for ($i = 1; $i <= 10; $i++) { echo $i; } Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted March 3, 2009 Share Posted March 3, 2009 My guess after re-reading your question would be that you are trying to rename files in a folder to consecutively numbered names. If so: <?php $count = 1; foreach(glob('*.jpg') as $filename) { copy($filename, $count.substr($filename, -4)); $count++; } ?> That should do it... You could also use unlink() after the copy to remove the original file. Hope that helps Quote Link to comment Share on other sites More sharing options...
anf.etienne Posted March 3, 2009 Author Share Posted March 3, 2009 thanks thats great......lol you guessed it straight away. thanks again everyone Quote Link to comment Share on other sites More sharing options...
anf.etienne Posted March 3, 2009 Author Share Posted March 3, 2009 i have tried it seperately from my main code and it works......but trying to incorporate it into my main code i cant figure out. here is the coding.....can someone point me in the right direction.....thanks again for the help before and for this in advance <? while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upload/$random_digit/$filename"; $tempFLDR = "upload/imgtemp/$filename"; //echo $_FILES['images']['type'][$key]; // echo "<br>"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); copy($_FILES['images']['tmp_name'][$key], $tempFLDR); chmod("$tempFLDR",0777); $count = 1; foreach(glob('*.jpg') as $filename) { copy($filename, $count.substr($filename, -4)); $count++; } $folderPath="upload/$random_digit/"; } } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 3, 2009 Share Posted March 3, 2009 <?php $images=array("pic_name_","pic_name_","pic_name_","pic_name_","pic_name_"); for($i=0; $i<count($images); $i++){ echo " <img src='{$images[$i]}.[$i].jpg' />"; } ?> Quote Link to comment Share on other sites More sharing options...
anf.etienne Posted March 3, 2009 Author Share Posted March 3, 2009 thanks red arrow but i just want to name the pictures with numbers i.e. 1.jpg 2.jpg 3.jpg 4.jpg 5.jpg etc etc it saves me having to recode my flash gallery Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.