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

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -