Current location: Hot Scripts Forums » Programming Languages » PHP » File Upload Help


File Upload Help

Reply
  #1 (permalink)  
Old 07-24-04, 09:57 AM
gezer77 gezer77 is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Texas
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
File Upload Help

Yeah, I have posted on here about how to check for a title in the form before uploading, and at first it worked. Then it just stopped working. The script was never changed, here is the code for php script
Code:
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<?php

    //check for title
    if ($title = ' ')
{

    echo 'Please enter a title and try again';
    exit();
}


     //Check first if a file has been selected 
     if (is_uploaded_file($_FILES['uploaded']['tmp_name'])) 
     { 

     //Get the Size of the File 
     $size = $_FILES['uploaded']['size'];

     //Get File Type
     $file_type = $_FILES['uploaded']['type']; 

     //Make sure that $size is less than 3MB and file type is right
     if ($size > 3000000) 
     { 

          //Print the error 
          echo 'File Too Large. Please select another File.'; 
          exit(); 
     }
   


       else if ( $file_type != "audio/mpeg" && $file_type != "audio/wav" )
    {

       //print error
       echo 'File Extension Incorrect. Please Select another file.';
       exit();

    } 
       
       

     

     //Move the File to the Directory of your choice 
     if (move_uploaded_file($_FILES['uploaded']['tmp_name'],'uploads/'.$_FILES['uploaded']['name'])) {

     

     //tell the user that the file has been uploaded 
     echo 'File Uploaded!<br>'; 
     echo 'It will be added to the licks page soon';
     

     //email me the title etc

     $myemail = "gezer77@theguitarlicks.com";

     if (!isset($visitormail));


     $todayis = date("l, F j, Y, g:i a") ;

     $subject = "New File Uploaded" ;

     $ip = getenv("REMOTE_ADDR");


     $message = " Title: $title \n
     IP = $ip \n ";
     
     $from = "From: $myemail\r\n";
     if ($myemail != "")
     mail($myemail, $subject, $message, $from);

     exit(); 

     } 
     else 
     { 

          //Print error 
          echo 'Unable to move the File'; 
          exit(); 

     } 
} 


else 
{ 

     //Print error 
     echo 'No File Selected';
     exit(); 

} 

?>
Heres the form code
Code:
<FONT face="verdana" size="0" color="7C1409">
<form action="upload.php" method="post" enctype="multipart/form-data">
Select a File to Upload:<br><br>
Title: <input type=text name="title" size="15"><br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="file" name="uploaded" value="Browse" size="16" style="background-color:#ffffff; border-color: #7C1409; border-width: 1; font-size: 10px; color:#000000; font-family: verdana, geneva, helvetica, arial;">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000"><br>
<input type="Submit" value="Upload File" style="background-color:#C0B07C; border-width: 1; border-color: #7C1409; font-size: 10px; color:#7C1409; font-family: verdana, geneva, helvetica, arial;"> 
</form></font>
Reply With Quote
  #2 (permalink)  
Old 07-24-04, 11:18 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Try this...

$title=$_POST['title'];
if($title){
echo "Title is required";
exit();
}
Reply With Quote
  #3 (permalink)  
Old 07-24-04, 12:29 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
yeah try mdhall's suggestion. If your host just upgraded PHP, this might be the problem.
Reply With Quote
  #4 (permalink)  
Old 07-24-04, 02:51 PM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mdhall
Try this...

$title=$_POST['title'];
if($title){
echo "Title is required";
exit();
}
Maybe he meant:
PHP Code:

 $title=$_POST['title'];

 if(!
$title){
    echo 
"Title is required";
    exit();
 } 
Another way, you can manipulate php environment by using php function: ini_set. however, be careful, using this way, somebody may do something nasty.
PHP Code:

ini_set('register_globals','1'); 

Reply With Quote
  #5 (permalink)  
Old 07-31-04, 06:44 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
A reason globals arent good is because of something like this:

Say this forum ran only with globals on, you could goto posting.php or something and use the textbox id in the url, and bang, you could post by refreshing, and refreshing, and refreshing...

It could also be used to run third party scripts on your site, to get passwords, to delete everything etc.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file upload csmaster2005 PHP 1 06-16-04 06:57 PM
Excel document containing records, need to save as a text file to upload to mysql bearslife PHP 1 06-05-04 03:24 AM
Image Upload, File Type Check, File Size Check CarBoffin PHP 3 04-13-04 02:26 PM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 04:14 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.