Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi!
i want to upload videos and music files using php but it's not working correctly.through this code imges are uploaded successfully but there is problem with video files ..i hv use php.ini to resolve the size prblem but still its not working..can u give me any code that works perfectly.
here is my code..
XML
<?php
ini_set('post_max_size', 5242880);    // Set upload limit (5MB)
ini_set('upload_max_filesize', 5242880);    // Enforce upload limit
ini_set('max_execution_time', 2400);    // Increase 'timeout' time

echo "<form enctype='multipart/form-data' name='form2' method='post' action='video.php?view_id=view'>";
if(isset($_REQUEST['Submit']))
{
print_r($_FILES['file2']);
$music=($_FILES['file2']['name']);
if($_FILES['file2']['error']>0)
{
    echo "error accured";
}
else
{
    move_uploaded_file($_FILES['file2']['tmp_name'],"uploadedMusic/".$_FILES['file2']['name']);
}

}

echo "<input name='file2' type= 'file'>";
echo "<input name='Submit' type='submit' value='upload music'>";
echo "</form>";
?>
Posted
Comments
Uday P.Singh 2-Jun-11 8:03am    
can you please tell , what kind of error are you getting??
hinzhonee 2-Jun-11 8:36am    
it doesnot give me any err.when i print this _FILES['file2']['error']..it prints 1

1 solution

Given your comment that $_FILES['file2']['error'] is 1, refer to the following extract from the PHP Manual:
Error Messages Explained
Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].

UPLOAD_ERR_OK
Value: 0; There is no error, the file uploaded with success.
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
UPLOAD_ERR_FORM_SIZE
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
UPLOAD_ERR_PARTIAL
Value: 3; The uploaded file was only partially uploaded.
UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.
UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
UPLOAD_ERR_CANT_WRITE
Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
UPLOAD_ERR_EXTENSION
Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.

This shows that error 1 is a size problem. Your real problem is that upload_max_filesize can not be altered using ini_set(). Refer to the list of php.ini directives in the PHP manual.

Cheers,
Peter
If this answers your question, mark it accepted. Vote anyway.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900