Jaswinder Posted May 15, 2013 Share Posted May 15, 2013 hi.. the code i am using for uploading is working fine few days back.. now giving some errors.. please solve it <form action="up1.php" method="post" enctype="multipart/form-data"><input type="file" name="up" /><input type="submit" value="submit"/></form> php <?php$up=$_FILES['up']['name'];copy($_FILES['up']['tmp_name'],"upload"."/".$up)?> where upload is a folder in which all the uploaded files are stored Error - - Warning: copy(): Filename cannot be empty in C:\xampp\htdocs\copy\up1.php on line 3 where is the mess ??? Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/ Share on other sites More sharing options...
Q695 Posted May 15, 2013 Share Posted May 15, 2013 (edited) Your file is missing/not pointed to the right name of the file. Edited May 15, 2013 by Q695 Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430112 Share on other sites More sharing options...
mac_gyver Posted May 15, 2013 Share Posted May 15, 2013 your code is not testing if the upload worked before using the uploaded file. try this - if($_FILES['up']['error'] === 0){ // upload worked without any error $up=$_FILES['up']['name']; move_uploaded_file($_FILES['up']['tmp_name'],"upload"."/".$up); } else { // upload failed, do some debugging echo 'Upload failed.'; echo '<pre>'; print_r($_FILES); echo $_SERVER['CONTENT_LENGTH']; } Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430173 Share on other sites More sharing options...
Q695 Posted May 15, 2013 Share Posted May 15, 2013 Adapt these videos: http://www.youtube.com/watch?v=T0Uv3VeTMR8 Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430232 Share on other sites More sharing options...
mac_gyver Posted May 16, 2013 Share Posted May 16, 2013 @Q695, sorry to pick on more of your replies, but the OP already has an upload script. he needs help finding out why it produces an error when trying to copy the uploaded file. posting a link to an upload tutorial with code that is no better than what the op has now, isn't specific to the problem. Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430339 Share on other sites More sharing options...
Jaswinder Posted May 16, 2013 Author Share Posted May 16, 2013 thanks for your answers..... i came to know my tmp_name is coming empty..but dont know why... any solutions?? how to fix this?? Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430341 Share on other sites More sharing options...
mac_gyver Posted May 16, 2013 Share Posted May 16, 2013 the code i posted in reply #3 would have helped determine why the tmp_name is empty. did you try that code? Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430343 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 (edited) None of the answers above are corect b/s of lack of server side knowledge. So, the copy php function is a simple and it's works only if the file already exist on the machine (server). When you try to upload a file from a local machine to the server the file is saved as a tmp, that's why mac_gyver proposal is correct to use move_uploaded_file (). Edited May 16, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430345 Share on other sites More sharing options...
Jaswinder Posted May 16, 2013 Author Share Posted May 16, 2013 yes @ mac_gyver i tried your code ... it is working fine for all files except for any songs and videos.. following error is coming Upload failed. Array( [up] => Array ( [name] => filename.mp3 [type] => [tmp_name] => [error] => 1 [size] => 0 ))6511567 is there any other method for mp3 or mp4 files ?? Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430462 Share on other sites More sharing options...
mac_gyver Posted May 16, 2013 Share Posted May 16, 2013 the problem isn't the method. you are getting an upload error due to the size of the file and your php settings. see this link - http://uk.php.net/manual/en/features.file-upload.errors.php Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430464 Share on other sites More sharing options...
Jaswinder Posted May 17, 2013 Author Share Posted May 17, 2013 how u came to know its a maxsize problem not of type or tmp_name as they are also coming blank ?? and also in php.in i changed max_upload_size still getting same error.... any other changes needed?? Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430641 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 Check this thread, especially my last post it would help you I guess. Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430643 Share on other sites More sharing options...
Jaswinder Posted May 17, 2013 Author Share Posted May 17, 2013 my php.ini shows this ;;;;;;;;;;;;;;;;; File Uploads ;;;;;;;;;;;;;;;;;; Whether to allow HTTP file uploads.; http://php.net/file-uploadsfile_uploads=On; Temporary directory for HTTP uploaded files (will use system default if not; specified).; http://php.net/upload-tmp-dirupload_tmp_dir="C:\xampp1\tmp"; Maximum allowed size for uploaded files.; http://php.net/upload-max-filesizeupload_max_filesize=2M; Maximum number of files that can be uploaded via a single requestmax_file_uploads=20 i changed upload_max_filesize=2048M but still same error Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430703 Share on other sites More sharing options...
Solution jazzman1 Posted May 17, 2013 Solution Share Posted May 17, 2013 Did you restart apache? Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430709 Share on other sites More sharing options...
Jaswinder Posted May 17, 2013 Author Share Posted May 17, 2013 thank you again .... problem solved .. i more question.. how this problem will be solved if same problem arises after uploading my website on hosting Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430712 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 (edited) The easiest way is to create a custom php.ini file which overridding the main php.ini file from the server, or to use ini_set setting new values. EDIT: The other way is to hack the server Edited May 17, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430718 Share on other sites More sharing options...
Jaswinder Posted May 17, 2013 Author Share Posted May 17, 2013 i think 1st option is better.. so how to create custom php.ini file Is i have to copy my local php.in and where to paste it... and how it will override the main php.ini Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430724 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 i think 1st option is better.. so how to create custom php.ini file Is i have to copy my local php.in and where to paste it... and how it will override the main php.ini That depends of your hosting provider, just check the helping guide manual that they provide to their customers. Quote Link to comment https://forums.phpfreaks.com/topic/278009-file-upload-error/#findComment-1430726 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.