otixz Posted August 29, 2007 Share Posted August 29, 2007 Hello, I've been doing a code that will transfer a file to another folder and preview it before adding it to the MYSQL database. Here is the code. <html> <form id="module1" name ="module1" method="post" enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>"> <?php if($_FILES['userfile']['name']=="") { ?> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td></td> <td></td> <td><b><center>Preview</td> <td></td> </tr> <tr> <td width="246"> <input name="userfile" type="file" id="userfile" onclick="submit()"> <td><img src=""></td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> <html> <?php } else { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; echo urlencode($fileName); $target_path = "E:\\xampp\htdocs\perpz/"; $target_path = $target_path . basename($_FILES['userfile']['name']); if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['userfile']['name']). " has been uploaded"; //header("Content-type: image/jpg"); //print $row['image']; ?> <html> <form id="module2" name ="module2" method="post" enctype="multipart/form-data" action="upload.php"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td></td> <td><b><center>Preview</td> <td></td> </tr> <tr> <td width="246"> <input name="userfile" type="file" id="userfile" value ="<?php echo $filename;?>" onclick="preview_image()"> <td><img src="browse.php?imageID=<?php print $fineName;?>" /></td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> <html> <?php } else { echo "There was an error uploading the file, please try again!"; } } ?> <script language="javascript"> function preview_image(){ window.location="http://localhost/perpz/browse.php"; } </script> There is no problem with the transfer of file to other folder.... The problem are: 1.) how will I view the transfered file using the img src tag? 2.) Every time after I transfered the image successfully to another folder, the input type file is " ". Anyone? Thank you! Grace Link to comment https://forums.phpfreaks.com/topic/67177-how-to-put-an-image-in-php-using-img-src/ Share on other sites More sharing options...
RoninStretch Posted August 29, 2007 Share Posted August 29, 2007 check this line.. <td><img src="browse.php?imageID=<?php print $fineName;?>" /></td> $fineName? Link to comment https://forums.phpfreaks.com/topic/67177-how-to-put-an-image-in-php-using-img-src/#findComment-336972 Share on other sites More sharing options...
watthehell Posted August 29, 2007 Share Posted August 29, 2007 use like this <img src="<?=$rs['image_field']?>" width="100" height="100" border="0" /> Link to comment https://forums.phpfreaks.com/topic/67177-how-to-put-an-image-in-php-using-img-src/#findComment-337040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.