geekygumshoe Posted June 21, 2010 Share Posted June 21, 2010 Alright. I've been beating my face in all night over this, I'm finally just gonna ask for help. I'm building a site for a used car sales business. They're using a weird program (what's basically a glorified excel sheet) to keep a list of all the cars they have available. I've been able to grab this list, turn it into a .csv, have it upload to the server, and I created a PHP script that displays all of the cars in that file, and inserts them into the database. Now - for some really stupid reason, that program doesn't upload the cars pictures when it uploads the .csv (or any other information). So I first decided I'd try some ajax (iframe) script, so that when all the cars in the file are displayed - they'd be able to easily upload a picture next to each car. However, every ajax script I found online ended up not allowing me to pass the "id" of the car in a post - so that way the upload script would take the image, upload it - then take the filename and add it to the database under the car's ID. Since that didn't work out, I'm thinking I'll have to create an array of all the ID's and their respective image's - have one submit button, and have the form/upload page go to work. If someone could point me in the right direction of getting started, or if this is even possible - I'd truly appreciate it. Thanks! Link to comment https://forums.phpfreaks.com/topic/205443-post-array-problems-with-files/ Share on other sites More sharing options...
kenrbnsn Posted June 21, 2010 Share Posted June 21, 2010 Code? Link to comment https://forums.phpfreaks.com/topic/205443-post-array-problems-with-files/#findComment-1075124 Share on other sites More sharing options...
gwolgamott Posted June 21, 2010 Share Posted June 21, 2010 Without your code not sure which way to point you... But I'd say whatever in the available car csv file you have that could be used as a unique identifier... name the cars photos that on upload and store them in a folder... that way you can just store the cars photos as links and use the name of the photos as the key to display the information from the csv. Link to comment https://forums.phpfreaks.com/topic/205443-post-array-problems-with-files/#findComment-1075131 Share on other sites More sharing options...
geekygumshoe Posted June 21, 2010 Author Share Posted June 21, 2010 The form, grabbing the image file, and assigning the ID of the car to the form in a while loop: <form method="post" action="upload.php" enctype="multipart/form-data"> <? //now get the cars $get_cars = "SELECT * FROM cars WHERE year > 0"; $get_cars_query = mysqli_query($dbc, $get_cars); while($show_cars = mysqli_fetch_array($get_cars_query)) { $car_id = $show_cars['id']; echo $show_cars['year'] .' '. $show_cars['make'] . ' ' . $show_cars['model'] . ' ' . $show_cars['color']; ?> <input type="hidden" name="id[]" value="<?php echo $car_id; ?>"> <input type="file" name="file[]"> <? echo '<br/><br/>'; } echo '<input type="submit" name="submit" value="Upload..."><br/><br/>'; ?> The upload script (where I want the ID and picture matched up in the database - I copied an array script I saw on here - it's probably done wrong. Right now I was just testing it seeing if it's even echo out the correct order of things... it's not showing me anything (white screen). Array's aren't my strong point... and ignore the upload script, copied it over from an old project.) <?php $id = $_POST['id']; $car = $_FILES['file']['name']; $data = array(); echo '<string>'; foreach ($data as $id => $car) { echo "$id = $car<br />"; } echo '</string>'; //define ('GW_UPLOADPATH', 'images/'); //$image3 = $_FILES['file']['name']; //$target3 = GW_UPLOADPATH . $image3; //move_uploaded_file($_FILES['file']['tmp_name'], $target3)) ?> Link to comment https://forums.phpfreaks.com/topic/205443-post-array-problems-with-files/#findComment-1075292 Share on other sites More sharing options...
gwolgamott Posted June 22, 2010 Share Posted June 22, 2010 It's dying probably on your echo // echo "$id = $car<br />"; echo $id." = ".$car."<br />"; Will print something like this: 2324dfe = Ford F-150 2009 Link to comment https://forums.phpfreaks.com/topic/205443-post-array-problems-with-files/#findComment-1075548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.