SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast PlayStone's Avatar
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extra spaces in image URL after upload!

    Hi,

    I have a little script to upload an image, like this:

    PHP Code:
    <form name="form1" method="post" action="" enctype="multipart/form-data"> 
    <input type="file" name="imagefile"> 

    <input type="submit" name="Submit" value="Submit">

    <? 
    if(isset( $Submit )) 

    //If the Submitbutton was pressed do: 

    if ($_FILES['imagefile']['type'] == "image/gif" || $_FILES['imagefile']['type'] == "image/pjpeg"){
    copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
        or die (
    "Could not copy");
        
            echo 
    "Name: ".$_FILES['imagefile']['name']."<br>"
            echo 
    "Size: ".$_FILES['imagefile']['size']."<br>"
            echo 
    "Type: ".$_FILES['imagefile']['type']."<br>"
            
    $temp_thumb_url = ("http://www.mysite.com/files/".$_FILES['imagefile']['name']);
    else { 
        
    //echo ($_FILES['imagefile']['type']);
                
    echo ""
                echo 
    "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")"
            } 
    }
    ?> 
    </form>
    All this very simple. But I am getting an extra space in from of each of the echo statements! Why is that?
    I tried using the str_replace(" ", "", $temp_thumb_url) but still get a space at the end of each line!

    Any ideas?
    Thanks.

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    What spaces, I tried it and everything looks normal. That being said I am surprised the above code works for you since it is missing a } and a $_POST around $submit.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At the end of the line you say....

    It migth just be the way the browser displays it, eg as in MS word you can, well, select the newline character (or it seems like it). Are you using view source?

    And either way, why is this bothering you?

    And yes, as an advice, I would also accept image/jpeg because that is how most browsers would send the type of the image (IE is somewhat ***** regarding this).
    - website

  4. #4
    SitePoint Enthusiast kidwizdumb's Avatar
    Join Date
    Oct 2003
    Location
    Ojai
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The New Guy
    What spaces, I tried it and everything looks normal. That being said I am surprised the above code works for you since it is missing a } and a $_POST around $submit.
    Looks like he has register globals turned on. It's better to leave them off though. Then any global variable is directly accessible by the user. Dr Pepper had a comment about this in "PHP and MySQL coding tips"

  5. #5
    SitePoint Enthusiast PlayStone's Avatar
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kidwizdumb
    Looks like he has register globals turned on. It's better to leave them off though. Then any global variable is directly accessible by the user. Dr Pepper had a comment about this in "PHP and MySQL coding tips"
    Thanks guys! I thought I had an extra space when selecting the line in the browser window.

    One more thing:
    Why can't I do this?

    PHP Code:

    $thumb_url 
    = ("http://www.tysus.com/contentmgmt/files/".$_FILES['imagefile']['name']);

    echo (
    "Thumbnail URL: ".$thumb_url);

    INSERT INTO mytable SET thumb_url=$thumb_url
    the ECHO displays the correct result but nothing gets uploaded to the database.
    Any ideas?
    Thanks.

  6. #6
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you have to do
    PHP Code:
    mysql_query("INSERT INTO mytable SET thumb_url='$thumb_url'"); 
    Just putting some text into the script won't do the trick, this is programming
    Edit:

    added single-quotes around $thumbs_url
    - website


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •