JPG sequence in PHP -


sorry elementary question not proficient in php. have php script puts photo in folder on website gets sent iphone. problem script overwrites previous jpg each time new photo uploaded. file name image.jpg. how can make php script force sequence each time new photo uploaded app (i.e. image_1.jpg, image_2.jpg, etc).

<?php $name = "image"; $path = "uploaded/".$name.".jpg"; $output = "{\"response\":\"false\"}";    if(move_uploaded_file($_files['image']['tmp_name'], $path)) {      $output = "{\"response\":\"true\"}"; } echo $output; ?> 

you're setting path , name on lines 2 , 3, use check if file exists, , if set $name image_$i , increment $i

<?php $i = 0; {     $name = 'image' . (($i > 0) ? '_' . $i : '');     $path = 'uploaded/' . $name . '.jpg';     $i++; } while (file_exists($path)); $output = "{\"response\":\"false\"}";    if (move_uploaded_file($_files['image']['tmp_name'], $path)) {      $output = "{\"response\":\"true\"}"; } echo $output; 

Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -