Count Images
- Started
- Last post
- 11 Responses
- browncrown
No. Not the distant relative of Dracula.
I have been looking forever for a php solution to count the number of jpgs in a directory, then pass it to a variable. I have seen functions that work, but when I try to use them, it breaks. Any easier solutions?
- rabattski0
what do you mean by it breaks?
- browncrown0
I guess I am just a php hack. I try to apply code from other examples that have worked, but it will not work.
There is a function I have that counts files. However, when I tried to use it, nothing.
Is there a way of doing it without using a function?
- rabattski0
what error do you get.
depends on the script if it needs to be a function or not. it doesn't really matter, i mean, it's not like because it's a function it doesn't work or something. a bug is a bug. but you have to call for that function though. if you don't nothing happens.
- rabattski0
here, this for sure works:
- rabattski0
btw i just noticed i left some unnecessary code in there. you can delete the defenition of the array and the definition of every single element if it's a jpg or a jpeg in the if loop.
- browncrown0
Thanks for all the help. I will take a look at the script.
Wish me luck. My biggest flaw is the actual application of the script.
- rabattski0
and leave that count=8 (first line) out. that's the actual script working. good luck though.
- browncrown0
At first application, it is working. I had it check my images directory and got a correct result. Now only if I can get it to work in conjunction with my other scripts.
Thanks again.
- rabattski0
just copy and paste that code into your code.
replace:
print "count=$count";with:
return $count;than read this:
- fusionpixel0
I would suggest also reading a basic intro to PHP book or some tutorials on line so you can understand the language.
It will save you headaches in the future... trust me
- browncrown0
I finally got it to work the way I needed. I think my mistake is that I wasn't properly calling upon the function. Something so simple in the scheme of it all.
I do need to get a book. However, I am learning a lot the hard way. I try to search before asking. Thanks for the help.