Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can't upload image problem

    Hi all.
    I have tried and tried to fix this but as I'm a newbie I'm having no luck. Got this setup/script made for us - paid a small amount - but am having this one problem.

    When I add a product we are supposed to browse for image which it uploads but just the path/image name is stored in database.

    The error I get is:
    Warning: Unable to create '/var/www/images/uploads/coaster.jpg': No such file or directory in /home/holidays/public_html/admin/addproduct.php on line 316

    Warning: Unable to move '/tmp/phpMaCLxK' to '/var/www/images/uploads/coaster.jpg' in /home/holidays/public_html/admin/addproduct.php on line 316
    product added successfully

    The code for connect.php (which includes the path) is:-

    <?
    define('UploadDir', $_SERVER['DOCUMENT_ROOT'] . '/images/uploads/' ); // replace /familytravel/images/upload with the path to your upload directory.
    define('DBUploadDir', '/images/uploads/'); // replace /familytravel/images/upload with the path to your upload directory. this will be used in URLS
    $cnx = @mysql_connect('localhost', 'user', 'password');
    if(!$cnx) {
    echo('Failed to log into database at this time');
    }

    $select = mysql_select_db('holidays_dest');
    if(!$cnx){
    echo('failed to select database');
    }

    function dateSplit($date)
    {
    //$splitdate[0] = year
    //$splitdate[1] = month
    //splitdate[2] = day
    $splitdate = explode("-", $date);
    return $splitdate;
    }
    ?>

    The line 316 of addproduct.php referred to in the error message is:-

    move_uploaded_file($_FILES['files']['tmp_name'], UploadDir . $_FILES['files']['name']);

    I have changed the path about a million times and the code for connect.php is what should apparantly work but doesn't.

    Thanking you for any help, Sheryll.
    Last edited by sticks; 10-17-2002 at 09:27 PM.

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is the directory set up with the right write permissions?

  • #3
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi.
    It is set up with 777 which apparantly is correct - although I'm new)

    Thanks, Sheryll.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The first thing you want to do is edit your first post and remove the database access password - not good form to be posting that in a public forum.

    Assuming the directory /uploads/ is in the right place (ie in /images/ from public-root) then the script should work. Also assuming your input-file form field is named 'files'.

    You could try adding
    touch(UploadDir . $_FILES['files']['name']);
    prior to the move_uploaded_file line and see if you get a different error return.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One more question...

    Is your administration panel running from the same server as the main site?

    You have addproduct.php in /home/holidays/public_html/admin
    and the images will be in /var/www/images/uploads/
    which sort of indicates they are different servers.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #6
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Okii and thanks for your replies. Have edited my post as suggested

    As far as I'm aware the administration panel is running from the same server as the main site but how do I tell? Where on earth does /var/www/ come from? I have never seen this until the error message.

    Thanks again, Sheryll.

  • #7
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi again.

    The input form field is name files.

    I added the extra line and tested again - now get this error message:-

    Warning: unable to create file /var/www/images/uploads/jamesdean.jpg because No such file or directory in /home/holidays/public_html/admin/addproduct.php on line 316

    Warning: Unable to create '/var/www/images/uploads/jamesdean.jpg': No such file or directory in /home/holidays/public_html/admin/addproduct.php on line 317

    Warning: Unable to move '/tmp/phpAhZKmv' to '/var/www/images/uploads/jamesdean.jpg' in /home/holidays/public_html/admin/addproduct.php on line 317
    product added successfully

    Is there anything else I should check?

    Thanks, Sheryll.

  • #8
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi again.

    This newbie is trying to learn by reading all I can find and have found out that /var/www is the "document_root" after running a phpinfo file.

    home/holidays/public_html etc is the path to where the html files are.

    I'm confused about what I should do next.

    Thanks, Sheryll.

  • #9
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi again.
    Have also learnt from phpinfo file that upload_tmp_dir has "no value". I thought the images were uploaded to a temporary directory so does this mean I have to make one and if so where would I do that?

    Thanks, Sheryll.

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right - let's first try to get the script working by pulling out/amending the bits that do not work....

    Firstly we need to find the top document that the server uses to parse addproduct.php. All this means is that if you had my_admin.php that then includes addproduct.php , the top document would be my_admin.php. If you actually have www.yourdoamin.com/admin/addproduct.php in the url then addproduct is the top document. Now, suss out which folder that document is in (eg addproduct.php would be in /admin/)

    Once you've done that, create a new folder in that folder called 'test' and chmod it to 777 (might need ftp for that).

    Now the 'get the script working' bit -
    If we use relative linking to define the move_to directory within the script, we can easily target our new folder. This is to ensure the upload to /tmp/ bit is working properly.

    Change
    move_uploaded_file($_FILES['files']['tmp_name'], UploadDir . $_FILES['files']['name']);
    to
    move_uploaded_file($_FILES['files']['tmp_name'],'test/'.$_FILES['files']['name']);

    and remove the touch() line now. All that did was try to create a blank file as a test.

    If you can save the image using relative paths, you should be able to takes the few steps neccessary to get it into the proper folder.

    Good luck Sheryll
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #11
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okii - you're brilliant

    Sorry for delay in replying but I've been away. Anyway I changed the script as per your instructions and guess what - no error messages
    The images are up there sitting in the test folder. They are not actually showing up on the page when you choose a product from the database but I presume that's cos the path in that part of the script points to the old folder.
    A white square box with red cross and no error messages is definately a step in the right direction.

    Hope you don't mind telling me what to do next. Thanks again, Sheryll.

  • #12
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Okii.

    I'm back
    Have changed the path in addproduct.php and also in connect.php to /admin/images/uploads/ and now the pic not only uploads it shows up. Very happy here.

    As the initial addproduct.php had UploadDir instead of the relative path I presume I now need to learn how to make it work this way. Also was wondering why it is done this way.

    Thanks, Sheryll.


  •  

    Posting Permissions

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