Jump to content

upload different file extensions with one form


web_master

Recommended Posts

Hi,

 

I use this simple script to upload files on server:

 

<?php
if ($_FILES["file"]["name"]) {
$destination = "images/".$request['file_id']."_file.pdf";
	move_uploaded_file($_FILES["file"]["tmp_name"], $destination);
}
?>

 

This mean example:  25_file.pdf

 

 

So, I want to use a same relations mean add ID but the extesion of file let be what is the original...

 

If I upload an file with extension xls that will looks like 25_file.xls with pdf 25_file.pdf ...

 

how recognise the PHP the extension and how can I do it with script?

 

thanx

$_FILES is a superglobal array that stores all data of the files uploaded in the last upload session. 

 

So you would need to use additional form inputs to allow additional file uploads

 

Note your uploader is very crude and dangerous

 

 

well, this is the form what will send the file

 

<form action="<?php print $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="35" />
<input type="submit" name="file_submit" value="SEND" />
<input type="hidden" name="file_id" value="<?php print $request['file_id'];?>" />
</form>

 

 

This is simple script, because this is the only way to understand how its work... If I miss something secure stuff - please tell me that

 

thnxs

the MAX_FILE_SIZE is a oldschool way to restrict size its not really super important

 

your input type needs to have a better than than "file" use "xls_upload" or "pdf_upload"

don't know why you have a file_id in the form.

 

your form should be

<form action="<?php echo $_SERVER['PHP_SELF'];?>"> method="post" enctype="multipart/form-data">
<input type="file" name="xls_file" />
<input type="file" name="pdf_file"/>
<input type="submit" value="submit" />
</form>
<?php
print_r($_FILES);
?>

 

 

cooldude832, sorry, I forgot why is import, mean file_id, because when I upload file there will be the explanation for a file.

 

If I upload the file, there will the visitor see this:

 

This is excell table for something | file size 100k | [and some icon]

 

When he click on "This is excell table for something" text this will download for him a 25_file.xls file.

 

so that why I need file_id - text will go in dBase.

 

I want to upload the files with only one "<input type="file" name="file" size="35" />"... if is possible, because I dont know what type (extension) of file will be uploaded.

 

<form action="<?php print $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<input type="text" name="file_explain" />
<input type="file" name="file" size="35" />
<input type="submit" name="file_submit" value="SEND" />
<input type="hidden" name="file_id" value="<?php print $request['file_id'];?>" />
</form>

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.