Results 1 to 4 of 4

Thread: How to upload images using PHP??

  1. #1
    Join Date
    Nov 2009
    Posts
    761

    How to upload images using PHP??

    I am developing a website in the language PHP. I cant understand how do I upload and display images using PHP. I am newly using this PHP to create a website, so I am not familiar how to do it. Whenever I click the SUBMIT button, it loads for a while and redirects me to a blank page. When I check the directory, I cannot find any images uploaded. Anyone who is familiar with this language, kindly suggest a solution.

  2. #2
    Join Date
    May 2008
    Posts
    2,792

    Re: How to upload images using PHP??

    I know the code to create an upload button in a php form. Hope this works and you can use this button to browse images in php:
    <?php
    // filename: upload.form1.php
    // first let's set some variables
    // make a note of the current working directory relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
    // make a note of the location of the upload handler script
    $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.processor.php';
    // set a max file size for the html upload form
    $max_file_size = 30000; // size in bytes
    // now echo the html page
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="style.css">
    <title>Form for upload button</title>
    </head>
    <body>
    <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
    <h1>
    Upload form
    </h1>
    <p>
    <input type="hidden" name="maximum" value="<?php echo $max_file_size ?>">
    </p>
    <p>
    <label for="file">File to upload:</label>
    <input id="file" type="file" name="file1">
    </p>
    <p>
    <label for="submit">Press to...</label>
    <input id="submit" type="submit" name="submit1" value="Upload me!">
    </p>
    </form>
    </body>
    </html>
    Last edited by Trio; 25-11-2009 at 11:53 PM.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,578

    Re: How to upload images using PHP??

    Try this stylesheet that I had used during making a website which had a feature to upload images using PHP:

    #Upload
    {
    width: 20em;
    margin: 1em auto;
    padding:0 2em 2em 2em ;
    border:1px solid #ccc;
    color: #555;
    background:#ddf;
    font: 1em garamond, comic sans ms;
    }

    #Upload h1
    {
    font: 2em bold garamond, comic sans ms;
    margin: 0;
    padding:2em 0;
    text-align:center;
    }
    #Upload label
    {
    float: left;
    width: 9em;
    }

    #Upload p
    {
    clear: both;
    }

    .blue{
    color:blue;
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,137

    Re: How to upload images using PHP??

    You are not getting any error on the click of submit button. That means you are going right and there is no error. To upload images using PHP, you have to include a code that will redirect you to a particular page . Now you wont get a blank page.

    <?php
    // filename: successful.upload.php
    ?><!DOCTYPE HTML PUBLIC "-//W4C//DTD HTML 4.01//EN"
    "http://www.w4.in/TR/html9/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <title>Upload success</title>
    </head>
    <body>
    <div id="Upload">
    <h1>Upload file</h1>
    <p>You have uploaded the file successfully</p>
    </div>
    </body>
    </html>

Similar Threads

  1. Replies: 6
    Last Post: 28-09-2011, 11:53 PM
  2. Replies: 9
    Last Post: 10-09-2011, 10:31 PM
  3. Replies: 3
    Last Post: 21-12-2010, 01:44 PM
  4. Replies: 5
    Last Post: 23-08-2010, 08:13 AM
  5. Replies: 2
    Last Post: 19-05-2009, 06:31 PM

Posting Permissions

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