Spudster Posted November 30, 2006 Share Posted November 30, 2006 Hi,The question I have is regarding php file upload. What i need is a way to check and see if a filename is taken before it is uploaded. PHP does this on its own, but you get some generic php fatal error. I want to make it so I can make something comes up, just like a warning that the filename is taken. Here is the script for that part:<?php if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } // Does the file have the right MIME type? if ($_FILES['userfile']['type'] != 'text/plain') if ($_FILES['userfile']['type'] != 'video/quicktime') { echo 'Problem: file is not a text document/Quicktime video'; exit; } // put the file where we'd like it $upfile = '/uploads/'.$_FILES['userfile']['name']; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo 'Problem: Could not move file to destination directory'; exit; } } else { echo 'Problem: Possible file upload attack. Filename: '; echo $_FILES['userfile']['name']; exit; } echo 'File uploaded successfully<br><br>'; ?>Any help would be great. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/ Share on other sites More sharing options...
Zane Posted November 30, 2006 Share Posted November 30, 2006 [quote]PHP does this on its own, but you get some generic php fatal error.[/quote]which line of code gives the error.?TIP..put the @ symbol in front of the offending function call to suppress that fatal 'generic' errorexample[code=php:0]$moveFile = @!move_uploaded_file($thisfile, $here);if(!$moveFile) show error[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/#findComment-132534 Share on other sites More sharing options...
Spudster Posted November 30, 2006 Author Share Posted November 30, 2006 I dont even know, lol which is pretty pathetic, but im assuming its the last else statement...i think Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/#findComment-132539 Share on other sites More sharing options...
Zane Posted November 30, 2006 Share Posted November 30, 2006 well .... it should tell you the line number in the Fatal errormake it do the error againand post it here along with where the line is Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/#findComment-132540 Share on other sites More sharing options...
Spudster Posted November 30, 2006 Author Share Posted November 30, 2006 now i am not getting anything. it says it wrote to the database and uploaded the file to the correct place, but nothing new is added to the db and the file is still in the folder Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/#findComment-132544 Share on other sites More sharing options...
Zane Posted November 30, 2006 Share Posted November 30, 2006 not sure if it has anything to do with it...but I would think soyou can get rid of all those exit functions.They stop you're script Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/#findComment-132546 Share on other sites More sharing options...
Spudster Posted November 30, 2006 Author Share Posted November 30, 2006 thanks ill try it out. sorry i couldnt reproduce my error, lol, if i find it ill repost Quote Link to comment https://forums.phpfreaks.com/topic/28940-file-upload/#findComment-132547 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.