-
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!";
}
//}
}
?>
-
Re: if else statement
You are using old deprecated variables. Use the $_FILES array instead of $HTTP_POST_FILES
-
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!";
}
}
}
?>
-
Re: if else statement
Do you have the HTML that submitted the page?
-
Re: if else statement
-
Re: if else statement
-
1 Attachment(s)
Re: if else statement
-
Re: if else statement
Could you put it in code tags - I do not have the application to open RAR files.
-
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"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </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"> </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"> </td>
</tr>
</table>
<p> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<div align="center"></div>
<div align="center"></div>
<p align="center"> </p>
</form>
</body>
</html>
-
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.)
-
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
-
Re: if else statement
i have change the php.ini configuration and change the maximize upload file to 10MB
-
Re: if else statement
-
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
-
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.