+ Reply to Thread
Results 1 to 10 of 10

Thread: PHP script file upload issue

  1. #1
    purpleman51 is offline New Bee
    Join Date
    Jan 2010
    Posts
    7
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP script file upload issue

    Hello-

    I have a PHP script for uploading files. It uploads the files to the correct directory just fine. But after the upload, the script cannot seem to see the uploaded files. Directory where uploaded files go is CHMOD 775. Uploaded files (image files for this example) are CHMOD 644. What I am trying to do is just display the image on the web page after upload. The "alt" text from the <img> tag is all that is displayed but the image is not. In fact using the full URL to the image does not work. Any suggestions?

    Thank you!
    Stephen

  2. #2
    Anna M.'s Avatar
    Anna M. is offline WeeHBie
    Join Date
    Dec 2008
    Posts
    453
    WHB Points this Month
    0.00
    WHB Points
    50.00
    Thanks
    2
    Thanked 6 Times in 3 Posts

    Default

    Please submit a ticket to the technical department at whbsupport.com. If you haven’t registered there yet, please do as the helpdesk requires separate registration.
    CS Team
    WebHostingBuzz.com

    Get the latest news and promotions by following us on Twitter and Facebook

  3. #3
    purpleman51 is offline New Bee
    Join Date
    Jan 2010
    Posts
    7
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I submitted a ticket and was told by support they won't handle it.

  4. #4
    Taras O. Guest

    Default

    Hi,

    Can you please post the ticket ID?

  5. #5
    dmaftei is offline dmaftei
    Join Date
    Apr 2007
    Location
    New Hampshire
    Posts
    14
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by purpleman51 View Post
    I have a PHP script for uploading files. It uploads the files to the correct directory just fine.
    Is that directory under your public_html? If it is, post your script here, let us take a look at it.

    Best,
    d

  6. #6
    purpleman51 is offline New Bee
    Join Date
    Jan 2010
    Posts
    7
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ticket ID: AKI-641917

    Thank you.

  7. #7
    purpleman51 is offline New Bee
    Join Date
    Jan 2010
    Posts
    7
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is the script:

    <?php
    if (isset($_POST["sendPhoto"])) {
    processForm();
    } else {
    displayForm();
    }

    function processForm() {
    if (isset($_FILES["photo"]) and ($_FILES["photo"]["error"] == UPLOAD_ERR_OK)) {
    if ($_FILES["photo"]["type"] != "image/jpeg") {
    echo "<p>JPEG photos only, thanks!</p>";
    } elseif (!move_uploaded_file($_FILES["photo"]["tmp_name"], "uploads/" . basename($_FILES["photo"]["name"]))) {
    echo "<p>Sorry, there was a problem uploading that photo.</p>" . $_FILES["photo"]["error"];
    } else {
    displayThanks();
    }
    } else {
    switch($_FILES["photo"]["error"]) {
    case UPLOAD_ERR_INI_SIZE:
    $message = "The photo is larger than the server allows.";
    break;
    case UPLOAD_ERR_FOPM_SIZE:
    $message = "The photo is larger than the script allows.";
    break;
    case UPLOAD_ERR_NO_FILE:
    $message = "No file was uploaded. Make sure you choose a file to upload.";
    break;
    default:
    $message = "Please contact your server administrator for help. Error value =" . $_FILES["photo"]["error"];
    }
    echo "<p>Sorry, there was a problem uploading that photo. $message</p>";
    }
    }

    function displayForm() {
    ?>
    <h2>Uploadng a Photo</h2>
    <p>Please enter your name and choose a photo to upload, then click Send Photo.</p>
    <form action="uptest.php" method="post" enctype="multipart/form-data">
    <div style="width: 30em;">
    <input type="hidden" name="MAX_FILE_SIZE" value="50000" />
    <label for="visitorName">Your name:</label>
    <input type="text" name="visitorName" id="visitorName" value="" /><br />

    <label for="photo">Your photo:</label>
    <input type="file" name="photo" id="photo" value="" />

    <div style="clear: both";>
    <input type="submit" name="sendPhoto" id="sendPhoto" value="Send Photo" />
    </div>
    </div>
    </form>
    <?php
    }

    function displayThanks() {
    ?>
    <h2>Thank You</h2>
    <p>Thanks for uploading your photo<?php if ($_POST["visitorName"]) echo ", " . $_POST["visitorName"] ?>!</p>
    <p>Here's your photo:</p>
    <p><img src="http://penguinguy.net/uploads/<?php echo $_FILES["photo"]["name"] ?>" alt="Photo" /></p>
    <p><img src="http://penguinguy.net/uploads/banner.jpg" alt="Photo" /></p>
    <?php
    }
    ?>

  8. #8
    dmaftei is offline dmaftei
    Join Date
    Apr 2007
    Location
    New Hampshire
    Posts
    14
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Your script works fine for me. (BTW, you have a typo: UPLOAD_ERR_FOPM_SIZE should be UPLOAD_ERR_FORM_SIZE).

    You clearly have a permissions problem, I get a "403 Forbidden" when I go directly to http://penguinguy.net/uploads/
    - Double check the permissions on uploads, should be 755, no need for 775.
    - Perhaps you have a .htaccess in your / and /uploads? If so, what's in them?

    Best,
    d

  9. #9
    purpleman51 is offline New Bee
    Join Date
    Jan 2010
    Posts
    7
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    d-

    Thank you for looking at it. I went in and changed the the directory permission to 755 and corrected the typo. It now works. Thanks again!!

  10. #10
    dmaftei is offline dmaftei
    Join Date
    Apr 2007
    Location
    New Hampshire
    Posts
    14
    WHB Points this Month
    0.00
    WHB Points
    0.00
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Any time.

    d

+ Reply to Thread

Posting Permissions

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