views:

30

answers:

2

Is there a way to pass an image file to a second page before uploading it to the data base?

Page 1

<input type="file" name="image" />

Page 2

<input style="display:none" name="image" value="<php? echo $_REQUEST['image']; ?>" />

page 3 -> database upload

$target_path = "uploads/";
$image_path_1 = $target_path . basename($_FILES['image']['name']);
move_uploaded_file($_FILES['image']['tmp_name'], $image_path_1);
+1  A: 

You can't do this :-(

You should upload the file in a temporary place, and store it's identifier (name/id/path/etc) somewhere (for example in the hidden input field or in a session value) to use in the second step. :-)

It's impossible to upload file without straight user action.

Ehsan
A: 

It kind of sounds like you want to present a "preview and accept" step to the user. If that is the case and you are uploading to the database if they accept, you could consider it a "publish" step. You could initially store the image in the database then change the status of the record after it is "published" from the second page.

Database Table:

id - int - primary key
file - image - the file
status - int - a custom status to show if the record has been published.

If you didn't want to modify the database table, you could create a new table to use as a temporary store.

Tim Carter