Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.