Jump to content

Uploading file


newstar

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.