Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/178382-uploading-file/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/178382-uploading-file/#findComment-943043
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.