Jump to content

ball420

Members
  • Posts

    141
  • Joined

  • Last visited

    Never

About ball420

  • Birthday 08/03/1979

Profile Information

  • Gender
    Male
  • Location
    Philadelphia, PA

ball420's Achievements

Member

Member (2/5)

0

Reputation

  1. I wanted to post the solution in case anyone ever needs it. What I ended up doing was creating a uniqid() and taking that unique id and changing the name in move_uploaded_file. but i needed these new unique names to be in an array so that i could INSERT into SQL. so what i did ws in my for loop everytime there was a new uniqid created i pushed it it the array. Sorry if it's confusing but you can look at my original code and compare to the working code below $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; $un_id =uniqid(); $uploaded_files = array(); $final_names = array(); $upload_directory = dirname(__file__) . '/car-images/'; //set upload directory /** * we get a $_FILES['images'] array , * we procee this array while iterating with simple for loop * you can check this array by print_r($_FILES['images']); */ for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; //this adds to the unique id for each item in the array $un_id++; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $un_id . ".jpg")) { $number_of_moved_files++; $the_new_names = $un_id . ".jpg"; array_push($final_names, $the_new_names); } } }
  2. what I'm doing is uploading multiple images, usually a different amount each time. That works fine until I added a for loop using the rename function to get the images just uploaded and rename them. What's happening now is only the last image in the $uploaded_files array is actually being uploaded and being renamed. Am i using the wrong syntax somewhere? Thanks in advance for the replies. if (isset($_POST['Submit'])) { $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; $unique_Id = uniqid(); $uploaded_files = array(); $upload_directory = dirname(__file__) . '/car-images/'; //set upload directory /** * we get a $_FILES['images'] array , * we procee this array while iterating with simple for loop * you can check this array by print_r($_FILES['images']); */ for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; $uploaded_files[] = $_FILES['images']['name'][$i]; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) { $number_of_moved_files++; } } } ///This is the loop that's making it only upload one image and rename it. for ($i=0; $i < $number_of_uploaded_files; $i++) { rename($upload_directory . $uploaded_files[$i], $upload_directory . $unique_Id . '.jpg'); }
  3. Hey all, I'm trying to upload multiple image(which works great) but the problem I'm having is when an image is uploaded it over-rights a previous image if they are the same name and the old one is gone. Solution: create a unique name for each image before it's uploaded, change the name and then upload it. I can't seem to figure the correct syntax. My thought was to take the image name and add a random number to the front of it. Am i going about this the right way? thanks for the replies in advance. code below if (isset($_POST['Submit'])) { $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; //creating my random number $random_digit=rand(0000,9999); $uploaded_files = array(); $upload_directory = dirname(__file__) . '/car-images/'; //set upload directory for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; $uploaded_files[] = $_FILES['images']['name'][$i]; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) { $number_of_moved_files++; } } } $image0 = $uploaded_files[0]; $image1 = $uploaded_files[1]; $image2 = $uploaded_files[2]; $image3 = $uploaded_files[3]; $image4 = $uploaded_files[4];
  4. I was curious if anyone knew of what the unique picture that you enter the numbers or letters to submit a form is called. and if anyone could guide me to some good tutorials for this. thanks a mill
  5. thanks for your help i was just explaining what I thought was going on. So i guess i have it down I'm going to get it all set up I think i got it now. thanks again
  6. this is what i have, $_SESSION['mycart']= $_POST['mycart'];."item_name|"; so that I understand the session named 'mycart' will be carried from page to page given that I carry this same session on each page using <?php session_start(); $_SESSION['mycart']= $_POST['mycart'];."item_name|"; session_write_close(); ?> then each product with the the form name="item_name" will line up when each product is submitted again with the same form name="item_name" but with different values. then at the end when i want to use all the vars collected in the session i use explode. thanks for your guidance I hope I didn't sound too confusing.
  7. so when i explode at the "checkout" the session will store all the input fields from each <form> </form> that's posted? thanks for the guidance much appricated
  8. here is my issue.... i have a small shopping cart meaning 20 items, i have it set up now that when you click on an item you go to the next page and the item info shows. Here is the code from the first page <form action="page2.php" method="post"> <input type="hidden" name="item_name" value="A-07"> <input type="hidden" name="amount" value="55.00"> <input type="hidden" name="no_shipping" value="2"> <input type="image" src="SM.gif" border="0" name="submit" > <img alt="" border="0" src="pixel.gif" width="1" height="1"> </form> what i want to do is to be able to go back to the product pages but still keep that item in the "session" so when you go to the checkout page all those items are there. I understand that i will need to use sessions but how do i differentiate between items if each item has the same variables within the <form></form>? I hope I'm explaining correctly. Thanks for the guidance it's much appreciated.
  9. thanks for the help everyone this was the solution i used thanks for the guidance $result = 54.89 * .07; echo number_format ("$result", 2);
  10. I want to display the only two numbers after I multiply. example when multiplying 54.89 * .07 the answer is 3.8423 i only want to echo two numbers after the decimal. Is there a way to do this? Can somone guide me in the right direction I have tried to search google and just can't seem to find anything. thanks in advance for the guidance
  11. thanks for your help i was really struggling with it. I did solve the issue what i ended up doing was on the submit of the form it calls two different scripts one for the email and the other to enter the info into the database. I didn't fix the problem with the script but i did get it to work. thanks again for your much appricated.
  12. cool, that def makes sense. thanks for the reply i'll just have to pay attention to my file size more than i normally do. thanks again
  13. i have started building my pages with <? include ("top.inc"); ?> and all my code for the page here and then <? include ("bottom.inc"); ?> does anyone know if this takes away from SEO? thanks fro the replys!
×
×
  • 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.