Jump to content

This will be the most complicated project I have ever done php-ajax-mySQL-javasc


Recommended Posts

Ok here we go!

I want to have a text box in which the user can input a url for a .jpg, .gif, or .png. I want it to download it to a certain folder and rename usbr0001, then usbar0002 ect. Then check it to be a valid image, and make sure it is in a certain size range.

then i want a script on  a certain page that will look up how many file (??how should i store this number??) pictures are save and display them, next to a checkbox, say, 100 per page.

I want to somehow save which pics the user select(this will be helped out be another forum, one that is specific to the system of user profile that I am using just  to let you know know that this will be done)

Finally I need to create a function(in php?) to display a random 5 out of the the pictures selected by the users in a looping animation.

Sorry that was kinda lengthy. So for the question, would some be able to give me an idea of what language to use for each section of that code, and a basic idea of how to do each(or one any that you know)

thank you.
Ive post on this forum on about 5 different an perfectly valid questions and I have got sarcasm in almost every reply.

I was NOT asking you to WRITE it I just want to know which language would be appropriate for each task, and if you knew of helpful hint maybe tell me about it.
I dunno if this should go in the PHP Help forum section or not... but here's some ideas that hopefully can get you started on your project... they may not work ;)

For the first part I believe it's possible to get an images contents with [url=http://www.php.net/file_get_contents]file_get_contents()[/url] you can then save it and verify it with [url=http://www.php.net/manual/en/function.exif-imagetype.php]exif_imagetype()[/url] (there may be a better way of doing this, just throwing it out there.) You might also be able to get an image type remotely using the [url=http://www.php.net/manual/en/function.exif-imagetype.php]exif_image_type()[/url], though I haven't tested it and it's possible that it might not work.

for the next part you could (possibly, and there might be a better way here as well) use [url=http://www.php.net/manual/en/function.scandir.php]scandir()[/url] to get all the files in the directory into an array, then you could use [url=http://www.php.net/manual/en/function.count.php]count()[/url] - 2 to get the number of files (- 2 is because [url=http://www.php.net/manual/en/function.scandir.php]scandir()[/url] has "." and ".." as items in the directory) you could then loop through the array created by [url=http://www.php.net/manual/en/function.scandir.php]scandir()[/url] to display the items.. let me give you some code so your head doesn't spin ALL the way around.

[code=php:0]
$files_array = scandir('/path/to/my/files/directory/'); // Get the files into an array
$num_files = count($files_array) - 2; // I don't know why you need this number... but you asked for it.

foreach($files_array as $file){ // loop through our array of files
    if($file != '.' && $file != '..'){ // make sure it's one of the files
          echo '<img src="path/to/image/' . $file . '" alt="" />'; // echo an image for each file
          echo '<input type="checkbox" name="file_request_array[]" value="' . $file . '" />'; // maybe a checkbox?
          // if you want to use a checkbox though, you would have to put this inside of a form, which isn't displayed on this code chunk
    }
}
[/code]

** Keep in mind when you use pagination to display the files (I'll cover this in the next paragraph) it will change the code above!

you would also want to use [url=http://www.google.com/search?hl=en&safe=off&client=firefox-a&rls=org.mozilla:en-US:official&hs=Tn4&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=define:pagination&spell=1]pagination[/url] to separate the items into pages, there are [url=http://www.phpfreaks.com/tutorials/73/0.php]many[/url] [url=http://www.google.com/search?q=php+pagination&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a]many[/url] [url=http://www.pixel2life.com/search/10/pagination/1/]many[/url] [url=http://www.phpfreaks.com/tutorials/147/0.php]tutorials[/url] on that subject around the internet.

you could then have them check some of the boxes, and submit it to a form that does the processing you mentioned.... you could do something like an animated .gif file to loop through the images? I'm not sure on this part exactly what you want since a lot of things can loop through images...

but choosing the random 5 images would be easy. Assuming you use the post method for your submission form and you use the same name for your checkboxes that I did in the above example you could do something like this...

[code=php:0]
$num_submitted_files = count($_POST['file_request_array']); // count submitted files
for($i = 0; $i <= 5; ++$i){ // loop 5 times
    $random_index = rand(0, $num_submitted_files - 1); // get a random index for a file
    $five_random_files[] = $_POST['file_request_array'][$random_index]; // add a random file to an array
}
[/code]

I hope I got you started well enough, keep in mind all of this is theoretical and a lot of my coding is trial and error so it's not 100% guaranteed to work.
wow thank you! Now I see that I wont need to keep track of that number, I was thinking I would need to know remember a running total so it would access the images from 1 to the image with that number



you've given me alot to read, in links and about these functions

thank you genericnumber1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.