News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP Help needed: Recognising an upload..

Started by Tristan Perry, August 18, 2004, 06:15:20 AM

Previous topic - Next topic

Tristan Perry

Hello all,
   This is what I'm working on at the moment:
http://tauonline.org/submit.php

If you look at the last 3 fields, there are 3 ways you can send your submission, and one is required:
  • Upload a file
  • Use a URL
  • Put the content in the text box

The last 2 work, however I can't seem to recognise if someones uploading a file or not. With my last host, they had register globals turned on and so all I had to do was use something like:

if($file_upload != ''){ check it, upload it } etc

Although my new host has register globals turned off and so that doesn't work. How am I supposed to see if someone has uploaded a file? I've tried everything:

  • if( isset($_FILES['upload']) )
  • if( $_FILES['upload']['size'] != 0 )
  • if( $_POST['upload'] )
etc but nothing seems to work. I'd appreciate any help with this.
  Thanks,
TauOnline.Org

P.s I know about 'is_uploaded_file()' but I also want to check that someone can't just put something like 'dajiosf' into the file upload box because 'is_uploaded_file()' wouldn't pick that up

Tomer

#1
Well you can validate from a few angles, this covers the main ones.

<?php

// Variable storage from form.

$userfile $HTTP_POST_FILES['userfile']['tmp_name'];

$userfile_size $HTTP_POST_FILES['userfile']['size'];

// Few checks.

if ($userfile == "none")
   {
          echo 
"No file selected.";
   }

if (
$userfile_size == "0")
   {
          echo 
"File size is 0; No file selected.";
   }

?>


Advertisement: