teknospr Posted April 27, 2012 Share Posted April 27, 2012 Good day: I have a simple uploader form to upload video files. FLV and mpg files will upload without problems. But mp4, m4v, ogg and webm files will not upload. I get this error: Warning: copy() [function.copy]: Unable to access in /mounted-storage/home7/sub007/sc30390-PTUD/**********.com/admin123/insertvideo.php on line 32 Error Video not loaded. I have read about adding the files in config/mimes.php but I do not see that folder or files in my hosting service (which is servage). Any help will be appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 Are you using any sort of CMS, framework, or some other third party script to upload things? Or just a simple run-of-the-mill file upload? Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 We cannot help you without seeing code. config/mimes.php is not a standard, are you using some php application that your forgetting to tell us about? Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 27, 2012 Author Share Posted April 27, 2012 Just a simple upload form. This is the code that does the actual upload: <html> <body bgcolor="#FFFFFF"> <?php $mydate = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : ""; // Your file name you are uploading $file_name = $HTTP_POST_FILES['video']['name']; $file_type = $HTTP_POST_FILES['video']['type']; // random 4 digit to add to our file name // some people use date and time in stead of random digit $random_digit=rand(0000,9999); //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$random_digit.$file_name; //set where you want to store files $path= "../videos/".$new_file_name; if($ufile !=none) { if(copy($HTTP_POST_FILES['video']['tmp_name'], $path)) { echo "Video agregado <BR/>"; //$new_file_name = new file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['video']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['video']['type']."<BR/>"; $con = mysql_connect("********", "*************","************"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("*********", $con); $sql="INSERT INTO videos (videoname, video, date) VALUES ('$_POST[videoname]', '$new_file_name', '$mydate')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Video añadido"; mysql_close($con); } else { echo "Error no se cargo video"; } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 I'm not sure where you got that example form but it is dated. $HTTP_POST_* has long ago been depricated. I'm surprised they are working at all. What version of php are you using? Use $_FILES instead. Also, you should be using move_uploaded_file in place of copy. I would start by fixing these things and seeing how you go. Quote Link to comment Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 Firstly you should be using $_FILES and not $HTTP_POST_FILES. Also, you should be using move_uploaded_file and not copy. With that out of the way, please put this in your script (anywhere as long as a file would have been uploaded at that point): echo '<pre>' . print_r($_FILES, true) . '</pre>'; Then post the output. Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 27, 2012 Author Share Posted April 27, 2012 Could you please give me a small example of the updated script? Quote Link to comment Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 Like I said, just put that code anywhere. For example here is the top of the code that you posted with that little snip added: <html> <body bgcolor="#FFFFFF"> <?php $mydate = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : ""; echo '<pre>' . print_r($_FILES, true) . '</pre>'; EDIT: And the snippet will give you all of the information contained in the $_FILES array which may be useful for debugging, so please post the output here. Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 I changed the script and this is what I get with the <pre> snippet: Array ( ) Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 I am getting Array ( ) Here is the updated script: <html> <body bgcolor="#FFFFFF"> <?php $mydate = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : ""; echo '<pre>' . print_r($_FILES, true) . '</pre>'; // Your file name you are uploading $file_name = $_FILES['video']['name']; $file_type = $_FILES['video']['type']; // random 4 digit to add to our file name // some people use date and time in stead of random digit $random_digit=rand(0000,9999); //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$random_digit.$file_name; //set where you want to store files //in this example we keep file in folder upload //$new_file_name = new upload file name $path= "../videos/".$new_file_name; if($ufile !=none) { if(move_uploaded_file($_FILES['video']['tmp_name'], $path)) { echo "Video loaded<BR/>"; //$new_file_name = new file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$_FILES['video']['size']."<BR/>"; echo "File Type :".$_FILES['video']['type']."<BR/>"; $con = mysql_connect("*********", "*******","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("*******", $con); $sql="INSERT INTO videos (videoname, video, date) VALUES ('$_POST[videoname]', '$new_file_name', '$mydate')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Video loaded"; mysql_close($con); } else { echo "Video not loaded"; } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2012 Share Posted April 28, 2012 If that output is after the form has been submitted, its likely that the size of the file exceeded the post_max_size setting (which causes both the $_POST and $_FILES arrays to be empty - http://www.php.net/manual/en/ini.core.php#ini.post-max-size ) or uploads are not enabled on your server or the form is invalid or the form does not have a type='file' input field. What size file did you attempt to upload? Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 Good day File size is 10MB. With flv files that are 6 and 7 MB the upload works fine. Also, I was able to upload an mp4 file of 7.5 MB. How can I increase the max upload size? And ensure that it does not time out? Quote Link to comment Share on other sites More sharing options...
plznty Posted April 28, 2012 Share Posted April 28, 2012 php_value upload_max_filesize 10M php_value post_max_size 20M in .htaccess or php.ini depending on your server Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 htaccess is disabled. Should I create a php.ini file? I don't know really have a php.ini file either. Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 I enabled htaccess in the server. It says I have to wait 3 hours. Will an htaccess file be generated or will I have to create one? Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 Good day: What I did was enabled htaccess, and created an .htaccess file with the following code: php_value upload_max_filesize 100M php_value post_max_size 100M php_value max_execution_time 6000 php_value max_input_time 6000 I know it seems overkill, but just wanted to make sure. Still, anything over 7MB gives me an empty array and does not upload. The upload form is multipart and works fine for anything under 8MB. Quote Link to comment Share on other sites More sharing options...
plznty Posted April 28, 2012 Share Posted April 28, 2012 Perhaps your hoster has its own max limit... I can't think of anything else I'm afraid. Quote Link to comment Share on other sites More sharing options...
teknospr Posted April 28, 2012 Author Share Posted April 28, 2012 Actually, they told me to increase to 100MB. Im gonna white some hours, maybe the settings do need 3 hours to be enabled. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.