Jump to content

[SOLVED] adding 1


anf.etienne

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/147736-solved-adding-1/#findComment-775537
Share on other sites

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/";
		}
	}

?>

Link to comment
https://forums.phpfreaks.com/topic/147736-solved-adding-1/#findComment-775626
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.