SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I cannot upload a jpg-file.

    Hi,

    I cannot upload a jpg-file.

    PHP Code:
    <?php
    $name 
    $_FILES['file']['name'];
    $tmp_name $_FILES['file']['tmp_name'];

    if (isset(
    $name)) {
        if (!empty(
    $name)) {
            
    $location 'uploads/';
            if (
    move_uploaded_file($tmp_name$location.$name)) {
                echo 
    'Uploaded.';
            } else {
                echo 
    'There was an error.';
            }
        } else {
            echo 
    'Please choose a file.';
        }
    }
    ?>

    <form actoin="index.php" method="POST" enctype="multipart/form-data">
        <input type="file" name="file" /> <br />
        <br />
        <input type="submit" value="Submit" />
    </form>
    Output:
    85.png

    Thank you!
    Last edited by SpacePhoenix; Sep 10, 2013 at 23:42. Reason: placed php tags around php code

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Check that the target folder exists and that it's not read only
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for reply. I did it. But It did not help.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    echo the value of $_FILES['file']['error'] what number does it contain?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    echo 'error: '.$_FILES['file']['error'];
    error: 0
    Code:
    <?php
    $name = $_FILES['file']['name'];
    $extension = strtolower(substr($name, strpos($name, '.') + 1));
    $tmp_name = $_FILES['file']['tmp_name'];
    $type = $_FILES['file']['type'];
    //$size = $_FILES['file']['size'];
    echo 'error: '.$_FILES['file']['error'];
    
    if (isset($name)) {
        if (!empty($name)) {
            if (($extension == 'jpg' || $extension == 'jpeg') && $type == 'image/jpeg') {
                $location = 'uploads/';
                if (move_uploaded_file($tmp_name, $location . $name)) {
                    echo 'Uploaded.';
                } else {
                    echo 'There was an error.';
                }
            } else {
                echo 'File must be jpg/jpeg';
            }
        } else {
            echo 'Please choose a file.';
        }
    }
    ?>
    
    <form actoin="index.php" method="POST" enctype="multipart/form-data">
        <input type="file" name="file" /> <br />
        <br />
        <input type="submit" value="Submit" />
    </form>

  6. #6
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please, sorry! I added the 'uploads' folder. Now it works. Thank you very much.


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
  •