aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-04-05 18:23:48 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-04-05 18:23:48 +0200
commitbf139cf4f0d6fb868d0f998d3213f7e681fbff92 (patch)
tree4ce8b63a8f16fa0cb1a9bf31a62a06a8013dbaf2
parent46b8f9d7a368f9ab35653edd726666ce17bedb39 (diff)
downloadphorkie-bf139cf4f0d6fb868d0f998d3213f7e681fbff92.tar.gz
phorkie-bf139cf4f0d6fb868d0f998d3213f7e681fbff92.zip
basic file upload works
-rw-r--r--data/templates/edit-file.htm5
-rw-r--r--data/templates/edit.htm2
-rw-r--r--data/templates/index.htm2
-rw-r--r--src/phorkie/Repository/Post.php24
4 files changed, 23 insertions, 10 deletions
diff --git a/data/templates/edit-file.htm b/data/templates/edit-file.htm
index b320d8d..53c2c01 100644
--- a/data/templates/edit-file.htm
+++ b/data/templates/edit-file.htm
@@ -17,11 +17,8 @@
<textarea name="files[{{fileid}}][content]" id="content_{{fileid}}" cols="80" rows="15" class="content">{{file.getContent}}</textarea>
<div class="row-fluid">
<div class="span9">
- &nbsp;
- <!--
- <label for="upload_{{fileid}}" class="inline">Replace with file upload:</label>
+ <label for="upload_{{fileid}}" class="inline">Replace with upload:</label>
<input type="file" name="files[{{fileid}}][upload]" id="upload_{{fileid}}" class="btn"/>
- -->
</div>
{% if not newfile %}
<div class="span3" style="text-align: right">
diff --git a/data/templates/edit.htm b/data/templates/edit.htm
index 19494b6..f1f4a51 100644
--- a/data/templates/edit.htm
+++ b/data/templates/edit.htm
@@ -2,7 +2,7 @@
{% block title %}Edit paste{% endblock %}
{% block content %}
-<form method="post" action="{{repo.getLink('edit')}}">
+<form method="post" action="{{repo.getLink('edit')}}" enctype="multipart/form-data">
<div class="control-group well pastedata">
<label for="description">Description</label>
<input type="text" name="description" id="description" value="{{repo.getDescription}}"/>
diff --git a/data/templates/index.htm b/data/templates/index.htm
index 31913bc..05c4c05 100644
--- a/data/templates/index.htm
+++ b/data/templates/index.htm
@@ -2,7 +2,7 @@
{% block title %}New paste{% endblock %}
{% block content %}
-<form method="post" action="/">
+<form method="post" action="/" enctype="multipart/form-data">
<div class="control-group well pastedata">
<label for="description">Description</label>
<input type="text" name="description" id="description" value="{{description}}"/>
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php
index b9d9be5..8cd9323 100644
--- a/src/phorkie/Repository/Post.php
+++ b/src/phorkie/Repository/Post.php
@@ -29,8 +29,12 @@ class Repository_Post
$this->repo->setDescription($postData['description']);
$bChanged = false;
- foreach ($postData['files'] as $arFile) {
- if ($arFile['content'] == '' && $arFile['name'] == '') {
+ foreach ($postData['files'] as $num => $arFile) {
+ $bUpload = false;
+ if ($_FILES['files']['error'][$num]['upload'] == 0) {
+ //valid file upload
+ $bUpload = true;
+ } else if ($arFile['content'] == '' && $arFile['name'] == '') {
//empty (new) file
continue;
}
@@ -39,8 +43,12 @@ class Repository_Post
$name = $this->sanitizeFilename($arFile['name']);
if ($name == '') {
- $name = $this->getNextNumberedFile('phork')
- . '.' . $arFile['type'];
+ if ($bUpload) {
+ $name = $this->sanitizeFilename($_FILES['files']['name'][$num]['upload']);
+ } else {
+ $name = $this->getNextNumberedFile('phork')
+ . '.' . $arFile['type'];
+ }
}
$bNew = false;
@@ -73,6 +81,14 @@ class Repository_Post
->addArgument($file->getFilename())
->execute();
$bChanged = true;
+ } else if ($bUpload) {
+ move_uploaded_file(
+ $_FILES['files']['tmp_name'][$num]['upload'], $file->getPath()
+ );
+ $command = $vc->getCommand('add')
+ ->addArgument($file->getFilename())
+ ->execute();
+ $bChanged = true;
} else if ($bNew || $file->getContent() != $arFile['content']) {
file_put_contents($file->getPath(), $arFile['content']);
$command = $vc->getCommand('add')