From: Christian Weiske Date: Thu, 5 Apr 2012 16:23:48 +0000 (+0200) Subject: basic file upload works X-Git-Tag: v0.1.0~48 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/bf139cf4f0d6fb868d0f998d3213f7e681fbff92?hp=46b8f9d7a368f9ab35653edd726666ce17bedb39 basic file upload works --- 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 @@
-   -
{% if not newfile %}
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 %} -
+
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 %} - +
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')