David-fethiye Posted May 18, 2006 Share Posted May 18, 2006 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 withthe [a href=\"http://localhost\" target=\"_blank\"]http://localhost[/a] path are displayed the otherswith the file:/// path are broken ???Any one know why this is ?HERE is the php codeUPLOAD.PHP calls UPLOAD_FORM.INCPHP 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). */ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD 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 ! Link to comment https://forums.phpfreaks.com/topic/9922-please-help-problem-with-image-upload/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.