Upload File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dev

    #1

    Upload File

    Dear All,

    I want to upload a file with PHP script. For that i use code given
    below. with this code my operation success but there is no file on my
    Server/Website
    Anyone help me to solve this problem.
    Thanks in Advance
    Dev

    Code for HTML Page

    <html>
    <body><form action="upload. php" method="post"
    enctype="multip art/form-data">
    <label for="file">File name:</label>
    <input type="file" name="file" id="file" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form></body>
    </html>

    code for upload.php Page

    <?php
    if (($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    && ($_FILES["file"]["size"] < 200000))
    {
    if ($_FILES["file"]["error"] 0)
    { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; }
    else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    if (file_exists("u pload/" . $_FILES["file"]["name"]))
    { echo $_FILES["file"]["name"] . " already exists. "; }
    else
    { move_uploaded_f ile($_FILES["file"]["tmp_name"], "upload/" .
    $_FILES["file"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    }
    }
    else
    { echo "Invalid file"; }
    ?>

    Output of the action:

    Upload: splendor.jpg
    Type: image/pjpeg
    Size: 160.4287109375 Kb
    Temp file: /tmp/php1DU5Tq
    Stored in: upload/splendor.jpg
  • Jerry Stuckle

    #2
    Re: Upload File

    Dev wrote:
    Dear All,
    >
    I want to upload a file with PHP script. For that i use code given
    below. with this code my operation success but there is no file on my
    Server/Website
    Anyone help me to solve this problem.
    Thanks in Advance
    Dev
    >
    This will store the file in the "upload" directory *relative to the
    current script's path*. Does this directory exist, and is it writable
    by the web server user? What's the return value from move_uploaded_f ile()?

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...