473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

reading random files from a folder

i have a folder which pictures of candidates from all the states but i need to get pictures of candidates for one state and put them in another folder my database contains directory of all the files in the picture folder
please help

Expand|Select|Wrap|Line Numbers
  1. //get the picture directory in an array
  2. $qry="select pix from corper";
  3. $rst=mysql_query($qry) or die (mysql_error());
  4. $num=mysql_num_rows($rst);
  5. while($r=mysql_fetch_assoc($rst)){
  6.  $pix[]=$r["pix"];
  7. }
  8. for($file as $pix[]){
  9. // set file to read
  10. $file = 'picture/'.$pix[].;
  11. // open file
  12. $fh = fopen($file, 'r') or die('Could not open file!');
  13. // read file contents
  14. $data = fread($fh, filesize($file)) or die('Could not read file!');
  15. // close file
  16. fclose($fh);
  17. echo $data;
  18. }
  19.  
it not working please whats wrong
Jul 31 '09 #1
3 2096
anfetienne
424 256MB
are the files being uploaded using a form? if so maybe within the pictures directory it should sort into the correct states folder on upload it would be alot easier.

if not then you would be needing to have some indication in those file names to do with states so that they can be picked up on

also this should have some indication of the array number but there maybe not be a need for the"[]" at the end try it without see if that helps

Expand|Select|Wrap|Line Numbers
  1. $pix[0]=$r["pix"];
  2.  
  3. or
  4.  
  5. $pix=$r["pix"];
  6.  
Jul 31 '09 #2
anfetienne
424 256MB
if you need help you will have to post the majority of your code from start to finish so we can see your process
Jul 31 '09 #3
dlite922
1,584 Expert 1GB
Your code looks fine from my quick scan. No anfetienne, his array is fine, your code would break it.

Just try printing $file and see what's inside it. Do a little debugging and tell us where the problem is, instead of just saying "IT doesn't Work" and run around with your hands in the air :)



Dan
Jul 31 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Oliver | last post by:
Hi, I wrote earlier this day about this problem but thought it had something to do with images. However, I found out that for some reason the readdir function is not working properly on my Suse...
1
by: Joel Goldstick | last post by:
I wanted to write a simple page to let me choose a directory and then list the files in it. The end goal was to make an easy way to copy all the file names in a directory. I tested with Opera7,...
4
by: SoulSniper | last post by:
Hi, I have been stuck on this for a few days now and have given up trawling through pages and pages of google results.. I'm just putting the finishing touches to a small game I've written....
4
by: Baz | last post by:
I want to randomly select some files from a source directory & copy them to a target folder for testing. How can I select files from the source directory randomly? I have thought about getting a...
1
by: Sahus Pilwal | last post by:
Hi, I hope someone can help me with this. I'm new to .NET and in fact server side programming and have a small query I'm sure... I'm using the System.IO Namespace with a For - each and If then...
10
by: howa | last post by:
for example, there are 10K files in the directory, given that i don't know if files name, is it possible to fetch a file randomly? thanks.
1
by: Sunshine192 | last post by:
Hi, I'm still kinda new to PHP so I could do with some advice. I'm using the code below to select and show a random image from a folder of images. rotate.php <?php // Make this the relative...
1
by: mortinrido | last post by:
Dear All, Currently i'm using VB6. I have several files of *.dgn or *.pdf within my folder. For example : I have chosen random folder (using dialog box) which contains some above files and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.