Commit 356cc4a7 authored by hancong03's avatar hancong03

修复不能自动创建路径的问题

Signed-off-by: 's avatarhancong03 <hancong03@baidu.com>
parent f33de2ea
<?php
return array(
'savepath' => dirname( __FILE__ ) . '/upload/'
);
\ No newline at end of file
...@@ -27,7 +27,9 @@ class FreeMindParser { ...@@ -27,7 +27,9 @@ class FreeMindParser {
'topic' => $data 'topic' => $data
) ); ) );
$filepath = getcwd() . '/upload/' . $data[ 'meta' ][ 'id' ] . '.mm'; $savepath = self::getSavePath();
$filepath = $savepath . '/' . $data[ 'meta' ][ 'id' ] . '.mm';
file_put_contents( $filepath, $content ); file_put_contents( $filepath, $content );
return $filepath; return $filepath;
...@@ -72,6 +74,19 @@ class FreeMindParser { ...@@ -72,6 +74,19 @@ class FreeMindParser {
} }
private static function getSavePath () {
$config = require( dirname(__FILE__) . '/../config.php' );
$savepath = $config[ 'savepath' ];
if ( !file_exists( $savepath ) ) {
mkdir( $savepath, 0770, true );
}
return pathinfo( $savepath . '/test', PATHINFO_DIRNAME );
}
private static function getTimeAndId () { private static function getTimeAndId () {
$timestamp = intval( microtime( true ) * 1000 ); $timestamp = intval( microtime( true ) * 1000 );
......
...@@ -163,9 +163,7 @@ class XMindParser { ...@@ -163,9 +163,7 @@ class XMindParser {
$info = self::getTimeAndId(); $info = self::getTimeAndId();
$imagePath = getcwd() . '/tmp/' . $info[ 'id' ] . $image[ 'suffix' ]; $imagePath = $image[ 'filepath' ];
rename( $image[ 'filepath' ], $imagePath );
$source['data'][ 'image' ] = array( $source['data'][ 'image' ] = array(
'filepath' => 'attachments/' . $info[ 'id' ] . $image[ 'suffix' ], 'filepath' => 'attachments/' . $info[ 'id' ] . $image[ 'suffix' ],
...@@ -173,12 +171,12 @@ class XMindParser { ...@@ -173,12 +171,12 @@ class XMindParser {
); );
array_push( $attachments, array( $attachments[] = array(
'filepath' => 'attachments/' . $info[ 'id' ] . $image[ 'suffix' ], 'filepath' => 'attachments/' . $info[ 'id' ] . $image[ 'suffix' ],
'origin' => $imagePath, 'origin' => $imagePath,
'type' => $image[ 'mime' ], 'type' => $image[ 'mime' ],
'meta' => $info 'meta' => $info
) ); );
} }
...@@ -200,7 +198,16 @@ class XMindParser { ...@@ -200,7 +198,16 @@ class XMindParser {
private static function move ( $meta, $path ) { private static function move ( $meta, $path ) {
$filepath = getcwd() . '/upload/' . $meta['id'] . '.xmind'; $config = require( diranme( __FILE__ ) . '/../config.php' );
$savepath = $config[ 'savepath' ];
if ( !file_exists( $savepath ) ) {
mkdir( $savepath, 0770, true );
}
$savepath = pathinfo( $savepath . '/test', PATHINFO_DIRNAME );
$filepath = $savepath . '/' . $meta['id'] . '.xmind';
rename( $path, $filepath ); rename( $path, $filepath );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment