Jump to content

Archived

This topic is now archived and is closed to further replies.

Drezard

File Upload Problem

Recommended Posts

Hello, How do i create a script that uploads a file to the webserver. But I only want files smaller then 1mb and Jpgs and Pngs. How do i do this?

- cheers, Daniel

Share this post


Link to post
Share on other sites
use an html file for the upload form and have it post to a php... you can find tons of them around the internet if you look.

Share this post


Link to post
Share on other sites
There's a tutorial for one here at [url=http://www.phpfreaks.com/tutorials/85/6.php]PHP Freaks[/url].

It says it's for beginners, and it looks as though it has lots of advanced features.

Regards
Huggie

Share this post


Link to post
Share on other sites
Your HTML page :
-----------------
<form name='file_upload' method='POST' action='Upload.php' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='submit' name='Upload' value='Upload'>
</form>

Upload.php
-----------
<?php

if($_POST['Upload']) {
    if(isset($_FILES[file][tmp_name]) && $_FILES[file][error]=='0') {
          if($_FILES[file][type]=='image/pjpeg' || $_FILES[file][type]=='image/x-png') {

              if($_FILES[file][size]<'1048576')  {
             
                    $src = $_FILES[file][tmp_name];
                    $des = $_FILES[file][name];

                    if(!move_uploaded_file($src,$des)) {
                        if(!copy($src,$des)) {
                              echo "Unable To Upload File!";
                        }
                    }
              }
              else {
                    echo "Upload Images less than 1 Mb size only";
              }
          }
          else {
              echo "Can Upload only JPG & PNG Images";
          }
    }
}

?>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.