newstar Posted October 20, 2009 Share Posted October 20, 2009 Hi guys I've got a bit of script that changes the file name when uploaded. The script executes when using firefox and chrome but fails to execute on IE, Safari and Opera, and i have no idea why. Hoping someone can shed some light on this for me. All advice greatly appreciated. Here is the code // Check for an uploaded file: if (isset($_FILES['upload'])) { // Validate the type. Should be msword. $allowed = array('application/msword', 'application/rtf', 'image/jpg'); if (in_array($_FILES['upload']['type'], $allowed)) { function isAllowed($fileName) { global $allowed; return in_array(end(explode(".", $fileName)), $allowed); } $target = "../uploads"; $target = $target . basename( $_FILES['upload']['name']) ; $ok=1; $explode = explode('.', $_FILES['uploaded']['name']); $extension = array_pop($explode); $newname = rand(0, pow(10, 5)).date("M d, Y").$_POST['email'].$extension; $basename = date("d.m.Y").$_POST['email'].$extension.( $_FILES['upload']['name']); $base_file = ( $_FILES['upload']['name']); // Move the file over. if (move_uploaded_file ($_FILES['upload']['tmp_name'], "../uploads/$newname.{$_FILES['upload']['name']}")) { //echo '<p><em>The file has been uploaded!</em></p>'; } // End of move... IF. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/178382-uploading-file/ Share on other sites More sharing options...
newstar Posted October 21, 2009 Author Share Posted October 21, 2009 Anyone got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/178382-uploading-file/#findComment-941435 Share on other sites More sharing options...
exally Posted October 23, 2009 Share Posted October 23, 2009 front. In form definition, multipart maybe?. There is little reason why Server side code should be effected by browser usage. Quote Link to comment https://forums.phpfreaks.com/topic/178382-uploading-file/#findComment-942616 Share on other sites More sharing options...
highrevhosting Posted October 23, 2009 Share Posted October 23, 2009 Hi guys I've got a bit of script that changes the file name when uploaded. The script executes when using firefox and chrome but fails to execute on IE, Safari and Opera, and i have no idea why. Hoping someone can shed some light on this for me. All advice greatly appreciated. Here is the code // Check for an uploaded file: if (isset($_FILES['upload'])) { // Validate the type. Should be msword. $allowed = array('application/msword', 'application/rtf', 'image/jpg'); if (in_array($_FILES['upload']['type'], $allowed)) { function isAllowed($fileName) { global $allowed; return in_array(end(explode(".", $fileName)), $allowed); } $target = "../uploads"; $target = $target . basename( $_FILES['upload']['name']) ; $ok=1; $explode = explode('.', $_FILES['uploaded']['name']); $extension = array_pop($explode); $newname = rand(0, pow(10, 5)).date("M d, Y").$_POST['email'].$extension; $basename = date("d.m.Y").$_POST['email'].$extension.( $_FILES['upload']['name']); $base_file = ( $_FILES['upload']['name']); // Move the file over. if (move_uploaded_file ($_FILES['upload']['tmp_name'], "../uploads/$newname.{$_FILES['upload']['name']}")) { //echo '<p><em>The file has been uploaded!</em></p>'; } // End of move... IF. Thanks Do you have the HTML front end? You need to make sure you have enctype="multipart/form-data" Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/178382-uploading-file/#findComment-943043 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.