I'm building a site with a three part process where companies can complete 开发者_运维问答a form, preview their listing, and if correct, submit that information to my database. The file process is:
- Forminput.php
- PreviewListing.php
- Insertrecord.php
One of the form fields allows users to upload their logo which i am storing for the Preview page with:
session_start();
$_SESSION['clogo'] = ($_FILES['clogo']['name']);
move_uploaded_file($_FILES["clogo"]["tmp_name"],
"temp/" . $_FILES["clogo"]["name"]);
This then lets me display the logo on the preview page with:
<img src = "temp/<?php echo $_SESSION['clogo'];?>" alt = "Company Logo"/>
The problem i'm facing however is i WAS just going straight to the direct insert php page with the INSERT query for MySQL, which uploaded the image to a folder and placed the file path in the table row for that particular company. This worked fine.
However now, because i have interupted the flow between $_POST and the Insert.php file, i can no longer do this. As i understand it, i have to store the image somewhere on the preview.php file to be able to display it on that page, however when it then comes to the next step in the process for database insertion, i don't know how to:
a) move the image to the final file folder.
b) delete the image from the temp folder.
c) add the path to the database row for that particluar listing so i can display it, along with the other row data, on the final approved page.
I have started a session on the preview page and stored everything from the form submission in hidden fields, which works absolutely fine with the INSERT query for all other info (Company name, location, url etc etc), but i dont' know how to get around my problem with the image.
For reference, my original MySQL insert query for the image/image path in the third step of the process (insert.php), and which worked fine, was:
$clogo = ($_FILES['clogo']['name']);
move_uploaded_file($_FILES["clogo"]["tmp_name"],
"avatars/" . $_FILES["clogo"]["name"]);
$sql = "INSERT INTO businformation (clogo)
VALUES($clogo')";
Can anyone advise?
Thanks Dan
OK, I stored the temporary image location on the preview page in another session variable and passed this onto the insert page, which then allows me to add the image location to the database for that particular entry.
Now i read it, it sounds totally obvious. Little steps, you know :)
I haven't figured out how to move the image to a final location yet, but for now this is fine.
Thanks to Marc B and jworrin for the security check.
Dan
精彩评论