What are the methods used to upload a file in PHP?
Is there anyway other than "submit" method?
Sponsored by: █ Sparkhost - Hosting Without Compromises! █ Hybrid Performance Web Hosting █ Spark Host Stream Hosting █ Hybrid IRC & IRCd Server Shell Accounts
PHP upload
Started by
Kaiba
, Jun 18 2008 06:15 PM
4 replies to this topic
#1
Posted 18 June 2008 - 06:15 PM
good plan + hard work + deep faith = great success
#2
Posted 19 June 2008 - 08:24 AM
Why would you not want to use the form POST method? I am guessing you are looking for an AJAX style upload script where no page refresh is necessary. Check out hxxp://www.webtoolkit.info/ajax-file-upload.html for an example.
#3
Posted 23 June 2008 - 01:43 PM
well, anyway,
how can I use the get method to save data to a file?
how can I use the get method to save data to a file?
good plan + hard work + deep faith = great success
#4
Posted 23 June 2008 - 02:42 PM
$myFile = "SomeFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $_FILES['variable']);
fclose($fh);
#5 Guest_RandomCode_*
Posted 24 June 2008 - 02:37 AM
Here is a script that i'v done for myself a couple time ago. It allows multifile upload and uses DOM to create the new fields. Those uploaded files have their name encoded with md5 of microtime plus filename and stored in a subdir which is configured to be the date of the upload.
Hopefully this will be helpfull to someone else than me.
Greetings
Hopefully this will be helpfull to someone else than me.
Greetings
<?php
$dest="./";
if (count($_FILES["pictures"]["error"])>0){
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
$dir=$dest.date("m_d_Y")."/";
if (!is_dir($dir) && strlen($dir)>0){
mkdir($dir, 0777);
}
move_uploaded_file($tmp_name, $dir.md5(microtime())."_".$name);
}
}
}
?>
<script language="javascript">
function addNovoFicheiro(){
//--------------------------------------------------------------------------------------------------------------------------------------
var input = document.createElement('INPUT');
var lineBreak = document.createElement('BR');
//--------------------------------------------------------------------------------------------------------------------------------------
input.setAttribute('type','file');
input.setAttribute('name','pictures[]');
document.getElementById('linhas').appendChild(input);
document.getElementById('linhas').appendChild(lineBreak);
//--------------------------------------------------------------------------------------------------------------------------------------
}
</script>
<form enctype="multipart/form-data" action="<?php echo basename($_SERVER['PHP_SELF']);?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1024000" />
<input type="file" name="pictures[]" />
<div id="linhas"></div><hr>
<input class="btn" type="button" name="button" id="button" value="Mais anexos" onClick='addNovoFicheiro();window.scroll(0,document.body.offsetHeight);'>
<input type="submit" value="Store" />
</form>
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












