mattal999 Posted September 7, 2008 Share Posted September 7, 2008 Hi, Basically, i'm trying to upload a file, say 1.jpg, to a folder using PHP. I am using this: <?php function is_uploaded_file2($filename) { if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { $tmp_file = dirname(tempnam('', '')); } $tmp_file .= '/' . basename($filename); return (ereg_replace('/+', '/', $tmp_file) == $filename); } if(isset($_POST)) { if(is_uploaded_file2($_FILES['mp3']['tmp_name'])) { if($_FILES['mp3']['type'] == 'audio/mpeg') { $files = $_FILES['mp3']; $tmpname = $files['tmp_name']; $name = $files['name']; if(move_uploaded_file($tmpname, 'upload/'.$name)) { CLIPPED and this works fine on my website when uploaded via FTP to my proper website, but not on localhost. It fails on is_uploaded_file2() Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/ Share on other sites More sharing options...
Adam Posted September 7, 2008 Share Posted September 7, 2008 What error do you get? And what version of PHP are you running on your local web server? Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635779 Share on other sites More sharing options...
mattal999 Posted September 7, 2008 Author Share Posted September 7, 2008 I don't get an error, this runs: echo is_uploaded_file2($_FILES['mp3']['tmp_name']); ?> <script> window.parent.document.getElementById("mp3upload").style.display='block'; window.parent.document.getElementById("progress").style.display='none'; window.parent.document.getElementById("donedev").style.display='block'; window.parent.document.getElementById("donedev").innerHTML='The file could not be uploaded!'; </script> And i don't get anything where i put echo "the function". I'm running PHP4 Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635783 Share on other sites More sharing options...
GingerRobot Posted September 7, 2008 Share Posted September 7, 2008 What do you mean by 'it fails on is_uploaded_file2()' ? Do you get any error messages? What actually happens? On a sidenote, this isn't a valid way of checking if the form's been submitted: if(isset($_POST)) That will always return true, since the superglobal arrays are always defined, regardless of if there's anything in them or not. Try using: if(count($_POST) > 0) Oh, and it'd really help if you indented your code properly. Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635785 Share on other sites More sharing options...
mattal999 Posted September 7, 2008 Author Share Posted September 7, 2008 basically, it doesn't upload to the tmp directory. Is it because it's on my local drive, and doesn't move it to the tmp_directory? Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635786 Share on other sites More sharing options...
wildteen88 Posted September 7, 2008 Share Posted September 7, 2008 Also note that superglobal variables are case-sensitive, $_FILES is not the the same as $_files I do not see the purpose of your is_uploaded_file2 function either. Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635788 Share on other sites More sharing options...
mattal999 Posted September 7, 2008 Author Share Posted September 7, 2008 is_uploaded_file2 is basically the same as is_uploaded_file. I just thought it might change the problem but it didnt work. Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635790 Share on other sites More sharing options...
wildteen88 Posted September 7, 2008 Share Posted September 7, 2008 As you are running this on a local install edit your php.ini and make sure erroir_reporting is set to E_ALL and display_errors is set to On. Make sure you restart your HTTP server (eg Apache, IIS etc) after modifying the php.ini. If there is any errors in your code they should be displayed during runtime. You may want to post your code in full too. Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635793 Share on other sites More sharing options...
mattal999 Posted September 7, 2008 Author Share Posted September 7, 2008 OK, i changed the max upload size in php.ini manually (because i tried it about 2 hours ago using code, which obiously didn't work!) and now it works fine. Thanks anyway. mattal999 Quote Link to comment https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/#findComment-635797 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.