1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Image Upload in PHP

Discussion in 'PHP' started by idz, Sep 20, 2007.

  1. idz

    idz New Member

    Joined:
    Sep 1, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to upload a image from my computer to the "Image" Folder created in C:\wamp\www\.(My Document root is set to C:/wamp/www//test) & when I run this program it should display the image in the same browser window.But the following code is not working.
    HTML:
    <html>
    <head><title>Upload Files</title>
    </head>
    <body>
    </br>
    <center>
    <form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="img"/><br>
    <input type="submit" value="click to upload"  name="sub">
    </form>
    <? php
    if(isset($_POST['sub']))
    {
    	$file=$_FILES["img"]["name"];
    	$dir="images/";
    	$tot_dir=$dir.$file;
    	if(move_uploaded_file($_FILES["img"]["tmp_name"],$tot_dir))
    	{
    		?>
    		<img src="images/<?php echo $file; ?> "border="0" />
    		<?php
    				}
    ?>
    </center>
    </body>
    </html>
    
    Any suggestion what is wrong with the above code?
    Any help would be greatly appreciated.
    Thanks
     
    Last edited by a moderator: Sep 20, 2007
  2. idz

    idz New Member

    Joined:
    Sep 1, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    I am getting the following error when i click the "Upload" button ->
    "Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\php10.tmp' to 'images/abc.jpg' in C:\wamp\www\prosenjit\upload.php on line 17"
    And,I am using Firefox Browser.
    Kindly if you guide me...
    Also, is these code line correct? ->
    <img src="images/<?php echo $file; ?> "border="0" />
    I feel there is somthing wrong :confused:
    Anyone there to guide me plzz? :rolleyes:
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    idz you seems to be not getting how to make posts in the forums and read the Before you make a query thread to make things clear.
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    The filesystem path and the URI path may not be the same, please check!
     

Share This Page