can you edit your post and put three ~ either side of your code block or indent each line by 4 spaces. we will then be able to see your problem better
Filename includes Backslashes also with stripslashes
I have got a the following problem: I have create a simple Image Upload Process like this.
public function postImage($id){
$filename = date('Y-m-d_H:i:s').".jpg";
$note=Note::find($id);
$destinationPath='/srv/www/htdocs/example.com/api/public/projects/'.$note->project_id.'/notes/'.$id."/images/";
$file = Request::file('image');
$file->move($destinationPath, $filename);
$image = new Image;
$image->filename='projects/'.$note->project_id."/notes/images/".$filename;
$image->note_id=$id;
$image->save();
$result= $this->respondWithItem($image, new ImageTransformer);
return $result;
}
When returning filename which is in this case path to file beginning from projects plus at the end the filename it always returns something like that projects/1/notes/images/2015-03-27_10:44:291.jpg I of course dont want to have backslashes in my response. I use a Transformer for that like this:
<?php namespace App\Http\Controllers;
use Image;
use League\Fractal\TransformerAbstract;
class ImageTransformer extends TransformerAbstract
{
public function transform(Image $image){
return [
'id' => (int) $image->id,
'filename' => $image->filename,
'note_id' => $image->note_id,
'updated_at' => strtotime((string)$image->updated_at),
'created_at' => strtotime((string)$image->created_at)
];
}
}
I tried everything from str_replace to stripslashes on the filename but it did not work. Am I missing something I am doing wrong? When returning just the filename directly in the controller the response is correct.
Yes, once you display it separately, it won't have the escaped forward slashes... Have you tried it in the app to display the image?
Please or to participate in this conversation.