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!";
}
//}
}
?>
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!";
}
}
}
?>
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.
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:
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
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.