...

View Full Version : little problem with images - please help !



jeddi
05-18-2006, 03:53 PM
Hi all !

I am writinga simple image uploading script and want to display the image that is uploaded
- preferably BEFORE it is sent by means of js.

BUT i also have encountered a silly problem !


First I can't get over this simple problem !!

My server is set up as localhost on :d/web/

in the following HTML file all the images show - as you'd expect !

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<img src="file:///D:/Web/fethiye/turkey.gif" border="2">
<img src="http://localhost/fethiye/images/town.jpg" border="2">
<img src="http://localhost/fethiye/turkey.gif" border="2">
<img src="file:///D:/Web/fethiye/turkey.gif" border="2">
</body>
</html>


BUT in my PHP file i get a problem - only the images with
the http://localhost path are displayed the others

with the file:/// path are broken ???

Any one know why this is ?

HERE is the php code

UPLOAD.PHP calls UPLOAD_FORM.INC


PHP Code:
<?php
/* upload.php
* CALLS upload_form.inc
*/

if (!isset($_POST[upload])) {
$message1 = "Enter File Path";
$message2 = " Now ";
include ("upload_form.inc");
} // endif
else {
if($_FILES['pix']['tmp_name'] == "none") {
$message1 = "File did not successfully upload.";
$message2 = "Check the file size. Must be less than 250K";
include ("upload_form.inc");
exit();
} // endif

if(!ereg("image",$_FILES['pix']['type'])) {
$message1 = "File is not a picture file.";
$message2 = "Please try a different file.";
include ("upload_form.inc");
exit();
} // endif

else {
$destination = 'd:\web\data'."\\".$_FILES['pix']['name'];
$temp_file = $_FILES['pix']['tmp_name'];
move_uploaded_file($temp_file,$destination);
$message1 = "File has been successfully uploaded.";
$message2 = "CONGRATULATIONS !";
include ("upload_form.inc");
exit();
} // end else
} // end else

?>

------------------------------------------

and now the form :


PHP Code:
<?php
/* upload_form.inc
* CALLED BY upload.php (and recalls it).
*/

?>

HTML 4.01 Transitional//EN">
<!-- Upload_form.inc
Description : displays the a form for uploading data
-->
<html>
<head>
<title>Untitled</title>

<script language="JavaScript" type="text/javascript">
<!--
function changeSrc1(who){
img=who.replace(who.substring(0,1),'file:///'+who.substring(0,1));//add 'file:///' before the drive letter
img=img.replace(/\\/g,'/');//replace all backslashes with forward slashes
document.getElementById('preView1').src=img;
} // end of function
-->
</script>

</head>
<body>

<img src="file:///D:/Web/fethiye/turkey.gif" border="2">
<img src="http://localhost/fethiye/images/town.jpg" border="2">
<img src="http://localhost/fethiye/turkey.gif" border="2">
<img src="file:///D:/Web/fethiye/turkey.gif" border="2">


<div style='position:absolute; left:20px; top:60px'>
<form enctype ="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name ="MAX FILE SIZE" value="500000">
<table width="400px" border="0" cellspacing="0" cellpadding="1">
<tr>
<td>Picture file path: </td>
<td>
<input type="file" id="x_pix1" size="50" onchange="changeSrc1(this.value)"
name="pix" value = "<?php echo $x_pix1 ?>">
</td></tr>

<tr><td>
<input type="submit" name="upload" value="Upload Picture">
</td></tr>
</table>
</form>
</div>

<div id='PreView1' style='position:absolute; left:30px; top:200px' >
<img id="preView1" width="120" height="120" />
<br>
- - - Picture 1 - - -
</div>



<div style='position:absolute; left:200px; top:300px'>
<?php echo $message1 ?><br>
<?php echo $message2 ?><br>
</div>

</body>
</html>

---------------------------------------------------

BTW the js script is not working yet - but thats another problem !

Please help if you can !

Thanks:)

jonnybinthemix
05-18-2006, 05:03 PM
hi mate,

take a look at my site: Fartingfish (http://www.fartingfish.com)

it seems that i have already written exactly what you are trying to get working.

Feel free to take a look at my source for ideas.

Hope that helps

Jon

jeddi
05-19-2006, 08:43 PM
Hi Jon

Thanks - i took a look at farting fish, great name!

do you have any idae why i get problems with my he file:/// path
images ??

ALSO - have you ever tried to display an image BEFORE it is uploaded by using javascript ?

thanks
Dave.

GJay
05-19-2006, 08:56 PM
you can't use file:// references in websites you want to work through a server.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum