Uploading/attaching files

Alvaro3663

New Member
I wonder how to upload/attach files to a website without using ftp programs.

I mean, like it is done here or in many websites, where there is a button that opens a window to browse on your computer files and upload from there.
 

Alvaro3663

New Member
Well, thanks.

What after that? I need to submit it. I want to upload a photo and I want it to appear in another page.
 

conor

New Member
Right well to submit it you need to create a form. Then to store the image somewhere is a whole other story... Here is a script I wrote a while back. Make sure that you have PHP installed and have given write access to the directory in which you want to store the files. This stores them in a directory called user-files.

Code:
<?php
        if(isset($_POST['save'])){
                $tmpname=addslashes($_FILES['file_name']['tmp_name']);
                $newdir='user-files';
                mkdir($newdir);
                `rm -fr "$newdir"/image* ; convert "$tmpname" -geometry 320x320 "$newdir/image.png"`;
        }
echo '
<form method="post">
   <input type="file" name="file_name" value="browse"/>
   <input type="submit" name="save" value="Save"/>
</form>
';

?>

This script uploads one file. Everytime you upload another file it overwrites the existing file so it may not be ideal for what you want. But it will give you a general idea. It will only work on a Linux server as well. It converts the image to the png format no matter what type of file you upload so it should only work properly with images.
 
Top