如何将已上载的文件移动到laravel4中的另一个位置。我将上传的文件保存在带有路径'public/images/temp/'的项目文件夹中的临时文件夹中。文件正在成功地上载到临时文件夹。但我要在这两者之间做个付款选择。因此,只有在付款成功的情况下,我才需要通过重命名临时文件夹将其从临时文件夹移到另一个文件夹,路径是'public/images/consult/'。
我尝试了FILE::Move()和FILE::delete(),但是没有工作。我使用的代码是:
$filename1 = Session::get('email_filename1'); //filename of file stored in temporary folder
$ext = substr(strrchr($filename1,'.'),1);
$newfilename1 = 'Email_'.Str::random(20).'_'.Session::get('patient_id').'.'.$ext;
$oldfile = public_path().'images/consultation_files/temp/'.$filename1;
$newfile = public_path().'images/consultation_files/'.$newfilename1;
File::move($oldfile, $newfile);如果有人知道,请分享你的解决方案。会很有帮助的..。
日志显示:
2015-02-05 11:27:54 log.ERROR: /var/www/html/myrpoject/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1429 Stack trace:#0 /var/www/html/myrpoject/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1050):Illuminate\Routing\Router->handleRoutingException(Object(Symfony\Component\Routing\Exception\ResourceNotFoundException))中的异常
:#1/var/www/html/myrpoject/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1014):Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
:#2/var/www/html/myrpoject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(530):Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
:#3/var/www/html/myrpoject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(506):Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
:#4 /var/www/html/myrpoject/public/index.php(50):照明\Foundation\Application->run()
:#5 {main}
发布于 2015-02-04 13:01:06
使用File::copy()方法
$source是你的源头,$destination是你的去处
if ( ! File::copy($source, $desitination))
{
die("Couldn't copy file");
}要删除文件,请使用File::delete($filename);,对于多个文件,请使用File::delete($file1, $file2, $file3);
如果失败,请按照lukasgeiter的建议,将app/storage/logs/laravel.log看作是
我建议检查一下File::exists(),然后执行File::delete($filename);
这里有更多的信息
https://stackoverflow.com/questions/28321948
复制相似问题