...

View Full Version : using input type=file



angrytuna
02-10-2004, 04:23 AM
Hello,

I am trying to get a handle on the "input type = file" tag. What I'd like to do is allow the user to upload an image file, and subsequently display the image in the gaining page.

Essentially, the code I'm using is like so:
[page1.php]


...
<form action="page2.php" method="post" enctype="multipart/form-data">
Image to Upload <input type="file" name="impath" />
...

[page2.php]


...
<img src="<?php print $_POST['impath']; ?>" />
...

which gives me nothing. I've also tried:


...
<?php print $_POST['impath']; ?>
...

which just gives me the filename of the file submitted, and not its contents. I would've expected the previous to give me at least a long string of binary data. What gives? Would appreciate any help.

AT

ez4me2c3d
02-10-2004, 05:06 AM
heres a really nice tutorial on uploading files in php4
http://www.zend.com/zend/spotlight/uploading.php

angrytuna
02-10-2004, 10:46 AM
That works beautifully, thank you.
One side note - tracing down the $HTTP_POST_FILES they use in the code samples, php.net had this to say:


The Variables defined for uploaded files differs depending on the PHP version and configuration. The autoglobal $_FILES exists as of PHP 4.1.0 The $HTTP_POST_FILES array has existed since PHP 4.0.0. These arrays will contain all your uploaded file information. Using $_FILES is preferred. If the PHP directive register_globals is on, related variable names will also exist. register_globals defaults to off as of PHP 4.2.0.

Replaced all instances of $HTTP_POST_FILES with $_FILES, still worked beautifully. Others may read more about it here (http://www.php.net/features.file-upload) .

Thanks again,

AT



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum