Results 1 to 15 of 15

Thread: if else statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Question if else statement

    for the code below is a upload video file...........i have try to uses a video file that bigger than the $MAX_FILE_SIZE and upload...but the if statement alway execute the message "you did not upload a file";

    can i know y?

    Code:
    <?php
         if (!is_uploaded_file($HTTP_POST_FILES['uploadfile']['tmp_name'])){
    	echo "you did not upload a file";
    	unlink($HTTP_POST_FILES['uploadfile']['tmp_name']);
         
         } else {
    	$MAX_FILE_SIZE = 10000000;
    
    	if ($HTTP_POST_FILES['uploadfile']['size'] > $MAX_FILE_SIZE){
    		echo "The Uploaded file is too large";
    		unlink($HTTP_POST_FILES['uploadfile']['tmp_name']);
    
    	} else{
    
    		$target_path = "VideoUploadFolder/";
    
    		$target_path = $target_path.basename($_FILES['uploadfile']['name']);
    
    	
    if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $target_path)){
    			
    			echo "the file ".basename($_FILES['uploadfile']['name']). " has been uploaded";
    			echo $HTTP_POST_FILES['uploadfile']['size'];
    		} else{
    			echo "there was an error uploading the file, please tryagain!";
    		}
    	//}	
         }
    ?>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    You are using old deprecated variables. Use the $_FILES array instead of $HTTP_POST_FILES
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: if else statement

    still the same, it never execute the message "The uploaded file size is too large"

    Code:
    <?php
         if (!is_uploaded_file($_FILES['uploadfile']['tmp_name'])){
    	echo "you did not upload a file";
    	unlink($_FILES['uploadfile']['tmp_name']);
         
         } else {
    	$MAX_FILE_SIZE = 10000000;
    
    	if ($_FILES['uploadfile']['size'] > $MAX_FILE_SIZE){
    		echo "The Uploaded file is too large";
    		unlink($_FILES['uploadfile']['tmp_name']);
    
    	} else{
    
    		$target_path = "VideoUploadFolder/";
    
    		$target_path = $target_path.basename($_FILES['uploadfile']['name']);
    
    	
    		if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $target_path)){
    			
    			echo "the file ".basename($_FILES['uploadfile']['name']). " has been uploaded";
    			echo $_FILES['uploadfile']['size'];
    		} else{
    			echo "there was an error uploading the file, please tryagain!";
    		}
    	}	
         }
    ?>

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    Do you have the HTML that submitted the page?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: if else statement

    ya....i have!!

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    Please post
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: if else statement

    here is my html form!!
    Attached Files Attached Files

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    Could you put it in code tags - I do not have the application to open RAR files.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: if else statement

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Upload Video file</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    .style1 {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    }
    -->
    </style>
    </head>
    
    <body>
    <form method ="POST" enctype ="multipart/form-data" action ="uploader.php">
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <table width="441" height="41" border="0">
        <tr>
          <td width="120" height="35"><div align="center" class="style1">Upload video file: </div></td>
          <td width="9">&nbsp;</td>
          <td width="288"><div align="left">
              <input type="file" name="uploadfile" >
              <input type="hidden" name="MAX_FILE_SIZE" value = "10000000"/>
          </div></td>
        </tr>
      </table>
      <table width="440" height="27" border="0">
        <tr>
          <td width="280"><div align="right">
            <input name="btnUpload" type="submit" id="btnUpload" value="Upload">
          </div></td>
          <td width="153">&nbsp;</td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <p align="center">&nbsp;</p>
      <div align="center"></div>
      <div align="center"></div>
      <p align="center">&nbsp;</p>
    </form>
    </body>
    </html>

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: if else statement

    Chances are that your web server or PHP configuration already intercept files > 10M. Check your php.ini and web server configuration. (I think it's max_post_size and max_file_size or something like that.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    And if you want to find out why the file wasn't uploaded make a called to print_r($_FILES) and check the error condition in the file upload. It should correspond to one of these:

    http://de.php.net/manual/en/features...oad.errors.php
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: if else statement

    i have change the php.ini configuration and change the maximize upload file to 10MB

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    And did it work?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: if else statement

    for less than 10MB can.........but i doing the validation to prevent user upload file that bigger than 10MB.......and it should be run the message said that file too large, but it execute the message said that didnt upload file

  15. #15
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: if else statement

    That behaviour is correct. Why would you want to waste bandwidth uploading a file then telling the user that they cannot save it. Instead you should check the error index of the file array.

    If it was equal to UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE then you can output the appropriate error message.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width