SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    two ways of pointing to a file...one doesn't work...why?

    I'm inserting an image into a database and when i use the http path to it it doesn't work...ie:

    this version doesn't work:
    PHP Code:
    $imagedir "http://www.website.com/whatever/images/"
    but this version does work:
    PHP Code:
     $imagedir "/home/blah/public_html/whatever/images/"
    im confused....

  2. #2
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's because the database doesn't start reading from the public part of the directory tree; it starts from the private one(s)?

    Most likely for security reasons.

  3. #3
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay....well how can i make it read from the "http://..." one....

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    What are you trying to do with this image directory? Just prepend it to the image filename or something else?

  5. #5
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm making an upload script and the user fills out a form along with uploading an image. And when they submit the form it inserts the info into a database and instead of inserting the image into the database it inserts the location of the image...and so the location im trying to mak it enter i wanted to begin with "http://..." instead of "/home/blah/public_html/..."

  6. #6
    SitePoint Addict shad0w's Avatar
    Join Date
    Aug 2003
    Location
    PA
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The simplest solution I can think of is to just strip away the "/home/blah/public_html/" and replace it with "http://www.yourwebsite.com/", but I'll look into it.

  7. #7
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The simplest solution I can think of is to just strip away the "/home/blah/public_html/" and replace it with "http://www.yourwebsite.com/", but I'll look into it.
    strip it away? what do you mean? you mean just replace it? that would be exactly what i've already done...how else would i have found out that it didn't work?

  8. #8
    SitePoint Addict shad0w's Avatar
    Join Date
    Aug 2003
    Location
    PA
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No I mean, using str_replace() or preg_match() remove the "/home/blah/public_html/" and then replace it with "http://yoursite.com" before it's added to the database.

  9. #9
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Post the code you are using.
    Mike
    It's not who I am underneath, but what I do that defines me.

  10. #10
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's the snippet that doesn't work w/ "http://.." but works the other way just fine:
    PHP Code:
    if(rename($_FILES['userFile']['tmp_name'], "http://www.whatever.com/images/")) 

  11. #11
    SitePoint Addict shad0w's Avatar
    Join Date
    Aug 2003
    Location
    PA
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already can see where your problem might come from. In the manual it specifically says not to use the rename() function to rename and move your files or you might encounter errors. I'd do something like this:
    PHP Code:
    move_uploaded_file($_FILES['userFile']['tmp_name'], "/images/$new_name"); 
    You can move and change the file name with move_uploaded_file(). Also, use relative locations, not exact, this way it won't matter, just typing "/images" is the same as "http://www.yoursite.com/images" and "/home/blah/public_html/images".

  12. #12
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just typing "/images" is the same as "http://www.yoursite.com/images" and "/home/blah/public_html/images".
    well...not really...part of the reason i was using exact instead of relative was b/c different files would be in different folders for orgaztional purposes and so it would have been easier to have the exact instead of having to adjust accordingly using "../images and ../../images, etc. etc."....but i'll figure something out...

  13. #13
    SitePoint Addict shad0w's Avatar
    Join Date
    Aug 2003
    Location
    PA
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really. Typing "/images" is the same as "http://yoursite.com/images", "/images/dir2" is the same as "http://yoursite.com/images/dir2", and "/images/dir2/dir3" is the same as "http://yoursite.com/images/dir2/dir3". Adding a "/" in front of a relative url just points to the base directory. You should really read up on relative urls man.

  14. #14
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay "man"...thanks

  15. #15
    SitePoint Addict shad0w's Avatar
    Join Date
    Aug 2003
    Location
    PA
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RockNRollPig
    Okay "man"...thanks
    Would you rather be "dude" or "mate"?

  16. #16
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think i prefer "rosheka"...."okay rosheka" would be nice

  17. #17
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay...shadow...i tried that and it didn't work...whenever i just use "/images/" it says "no such file or directory"...but when i use "/home/username/public_html/images/" it works just fine....any ideas?


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
  •