dk4210 Posted November 30, 2010 Share Posted November 30, 2010 Hello Guys, I have a var that contains sub strings like this test058.gif,test1058.gif,test698.jpg, I want to be able to count how many times the images appear How would I do that with substr_count? I tried this $subn = $_SESSION['fname'] . $_SESSION['lname'] ; foreach (glob("temp_photo/$subn*.*") as $filename3) { // echo "$filename<br>"; $string = $filename3; $filename4 = basename($string); $phstring2 .= $filename4 . ","; echo $phstring2; echo substr_count($phstring2, ','); } But didn't work correctly.. Thanks for your expert help Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/ Share on other sites More sharing options...
AbraCadaver Posted November 30, 2010 Share Posted November 30, 2010 glob() returns an array, just count it: $files = glob("temp_photo/$subn*.*"); $count = count($files); Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141448 Share on other sites More sharing options...
dk4210 Posted November 30, 2010 Author Share Posted November 30, 2010 Thanks.. That worked... Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141477 Share on other sites More sharing options...
dk4210 Posted November 30, 2010 Author Share Posted November 30, 2010 Abra, I do have one more question if you have a second.. How do i check to see how many fines are in a directory without refreshing or submitting (POST) Basically what I want to do is this I have an upload feature on the page and I want to allow up to 8 images to upload and when the user uploads the 8th image I want the upload option to disappear.. This would do the trick if I was submitting the form. $subn = $_SESSION['fname'] . $_SESSION['lname'] ; $files = glob("temp_photo/$subn*.*"); $count = count($files); echo $count; if (count < { echo "upload_html"; } I think this will have to be done with ajax.. Any input? Thanks, Dan Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141495 Share on other sites More sharing options...
AbraCadaver Posted November 30, 2010 Share Posted November 30, 2010 Each time they upload you could increment a $_SESSION['upload_count'] var and then check it before displaying the form. Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141500 Share on other sites More sharing options...
dk4210 Posted November 30, 2010 Author Share Posted November 30, 2010 hmm that's interesting.. The problem is that the upload form displays in the entire form. Short of submitting will checking the session upload count and cause the upload form to disappear when 8 images have been uploaded? Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141515 Share on other sites More sharing options...
AbraCadaver Posted November 30, 2010 Share Posted November 30, 2010 hmm that's interesting.. The problem is that the upload form displays in the entire form. Short of submitting will checking the session upload count and cause the upload form to disappear when 8 images have been uploaded? I don't understand. To upload 8 files they will have to submit 8 times yes, or do you have it constructed some other way? Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141520 Share on other sites More sharing options...
dk4210 Posted November 30, 2010 Author Share Posted November 30, 2010 My Mistake. I am using an ajax uploader here - http://valums.com/ajax-upload/ Link to comment https://forums.phpfreaks.com/topic/220266-substr_count-help/#findComment-1141524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.