# PHP script to upload and display images?



## Leiki

Does anyone know of a simple PHP script that allows users to upload an image and then have it display on another page? Thanks.


----------



## COBOLdinosaur

Take a look atthis scripting

Yhat will get the image there, but if you are looking for it to immediately show up on the a page, then you will have to re-generate the page with the new image added; modify the script that write the page on the fly, or if it is a static page re-write it dynamically.

You are not giving us enough infomation about what you are doing so I all I can give you is broad general options.


----------



## Leiki

Thanks for your reply, but whenever I press submit it just loads for a while and then does nothing else. I checked my directory and nothing got uploaded. I need something like that, but something that actually works and have the picture be shown on a certain page.


----------



## COBOLdinosaur

There is probably a permissions problem on the folder you are going to.

Post your code please.

Do you have root acess on the server or just a control panel?


----------



## Leiki

Ah, I chmod'd my dir to 777, except now whenever I submit, it says "Warning: copy(files/picture.gif) [function.copy]: failed to open stream: No such file or directory in /fpgs/fpgshttpd/tajeko/upload/index.php on line 13
Could not copy". Here is my code:



PHP:


<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/gif"){ 
    copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
    or die ("Could not copy"); 
        echo "";
        echo "Name: ".$_FILES['imagefile']['name']."";
        echo "Size: ".$_FILES['imagefile']['size']."";
        echo "Type: ".$_FILES['imagefile']['type']."";
        echo "Copy Done....";
        } 
        else {
            echo "

";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")
";
        }
} 
?>


----------



## COBOLdinosaur

That just looks like the path is not set correctly.

How are you setting the path?


----------

