Jump to content


Photo

File Upload Problem


  • Please log in to reply
4 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 14 September 2006 - 06:42 AM

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

#2 geoffl1

geoffl1
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 14 September 2006 - 06:44 AM

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.

#3 laide234

laide234
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 14 September 2006 - 09:02 AM

This might be of some help...

http://www.nstoia.co...esize/index.php

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:13 AM

There's a tutorial for one here at PHP Freaks.

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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 rajeshrhino

rajeshrhino
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 14 September 2006 - 09:25 AM

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";
          }
    }
}

?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users