SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help getting really simple upload to work

    Arrgh, I've read a few tutorials, read a few articles - and in the end it seems that no one really knows the 'right' way to upload images, or a way that works universally. I'm using this code:

    PHP Code:
        $uploadlocation ABSPATH "images/products/";
        
    $tloc $uploadlocation "t/" $_POST['id'] . ".jpg";
        
    $floc $uploadlocation "f/" $_POST['id'] . ".jpg";
        
    move_uploaded_file($_FILES['thumbnail']['tmp_name'], $tloc);
        
    move_uploaded_file($_FILES['full']['tmp_name'], $floc); 
    $tloc and $floc are correct, when I echo them out I get something to the effect of "/var/www/html/images/products/t/my_unique_id_here.jpg" which is what it seems to me is right. However, nothing is happening. No error. No file upload. HOw do I even begin to figure out what when wrong? Do I need to set some PHP settings somewhere? My server's running Ensim if that makes a difference (sometimes does).

    Any help appreciated
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You will need to make sure that the permissions are set right. Which means that Internet Guests will need to have the right to write to your upload directory. That is probably the crux of the problem with your script.

    You could also add some error handling to your script to make it a bit more intuitive.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  3. #3
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    both /var/www/html/images/t and /var/www/html/images/f are CHMODed to 755, I have that right - right?
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    That should be fine. What browser/client are you trying to run the script from? IE, Moz, Firefox?

    I just noticed that with Firefox, mine isn't working however in IE it's fine.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  5. #5
    SitePoint Member
    Join Date
    Aug 2003
    Location
    London
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try CHMODingthe folder you want to upload to to 777

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Actually 755 should be fine. I'll CHMOD 777 while testing if I'm having trouble but otherwise I'd go with 755 or less.

    How are you making out?

    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  7. #7
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not so well =/ Fails in IE as well. I can't get an error, I can't get anything. Is there a way to see if move_uploaded_file actually worked? Or any server settings that may be restricting me?
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I think the problem may be with the script.

    I can see the move_uploaded_file(); part but not the actual uploading with HTTP. move_uploaded_file only moves files once they have been uploaded in the first place.

    CHmod 755 should be fine.

    More info on move_uploaded_file():
    http://ca.php.net/manual/en/function...oaded-file.php

    More info on uploading:
    http://ca.php.net/manual/en/features.file-upload.php

    I've attached a really simple php uploading script that you can use as a base to start with. It's renamed to upload.txt and will upload txt, html, gif, jpeg files to a directory above called "source". It's not great but it'll tell you if the upload didn't work.

    Cheers - Andrew

    PS: I think attachments take a while to be authorised so it may not appear immediately.
    Attached Files Attached Files
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  9. #9
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, while I'm waiting for that to be approved, I've re-read those pages again and it seems like mine should work. It say by default, anything sent through $_FILES is uploaded to a temp directory. However, I think I *may* have found the solution, it mentions some stuff about safe mode - and to be completely honest, I'm not entirely sure what it means by it, but I figure that's about the only thing that can be stopping me now.
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  10. #10
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'oh! Just fixed my problem =/

    Stupid me didn't put in the <form> tag: enctype="multipart/form-data" This causes everything but the file information to be uploaded (i.e. the name, etc). All is working now though Thanks for your help everyone!
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Right on!

    Now you have to go sweep up all that hair you pulled out over the last few days
    I'm glad you got that worked out and in the end it's an easy fix.

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •