Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5

Thread: PHP file upload

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    19
    Member #
    13406
    Hi again.
    I have a simple PHP file upload form that ive been using to let folks upload pix to my site, to the images folder.
    I have one favore to ask
    Can someone edit this code so it generates a page with the uploaded file after the person has uploaded the file. Or so it atleast gives them a link to the file they uploaded. So they can find it quickly. I dont know much about PHP, i found this form on google and it works good. But its not like id know what to do if someone just told me... :S Can be that hard to generate a link to the file after the upload..?
    lol anyway.. thanx.
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?php
    define ("MAX_SIZE","1000");
    function getExtension($str) {
    $i = strrpos($str,".");
    if (!$i) { return ""; }
    $l = strlen($str) - $i;
    $ext = substr($str,$i+1,$l);
    return $ext;
    }
    $errors=0;
    //checks if the form has been submitted
    if(isset($_POST['Submit']))
    {
    $image=$_FILES['image']['name'];
    if ($image)
    {

    $filename = stripslashes($_FILES['image']['name']);

    $extension = getExtension($filename);
    $extension = strtolower($extension);
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
    {
    echo '<h1>Unknown extension!</h1>';
    $errors=1;
    }
    else
    {

    $size=filesize($_FILES['image']['tmp_name']);
    if ($size > MAX_SIZE*1024)
    {
    echo '<h1>You have exceeded the size limit!</h1>';
    $errors=1;
    }
    $image_name=time().'.'.$extension;
    $newname="images/".$image_name;
    $copied = copy($_FILES['image']['tmp_name'], $newname);
    if (!$copied)
    {
    echo '<h1>Copy unsuccessfull!</h1>';
    $errors=1;
    }}}}
    if(isset($_POST['Submit']) && !$errors)
    {
    echo "<p>File Uploaded.</p>";
    }
    ?>
    Let the rabbits wear glasses.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Underneath where your code outputs "File Uploaded, put this

    PHP Code:
    echo "<a href=\"images/$newimage\">$newimage</a>"
    Which gives you something like..
    PHP Code:
    if(isset($_POST['Submit']) && !$errors)
    {
    echo 
    "<p>File Uploaded.</p>";
    echo 
    "<a href=\"images/$newimage\">$newimage</a>";


  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Actually,

    PHP Code:
    if(isset($_POST['Submit']) && !$errors) {
        echo 
    "<p>File Uploaded.</p>";
        echo 
    "<img src=\"$newname\" alt=\"\" /><br />";


  5. #4
    Junior Member
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    19
    Member #
    13406
    Sweet.. Thanks..
    Let the rabbits wear glasses.

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yeah, oops

    I dummy tested it to b sure and used my own code.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:05 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com