base64_decode这不起作用

时间:2016-02-16 19:09:50

标签: php image symfony file-upload base64

我在symfony2.6创建的角色中遇到了问题。我正在把我知道的话放在哪里给出错误,因为经过测试并且它正确地获取了我的数据。

如果我将其复制并放在site上,则会生成图像。

$dat = preg_split("/,/", $base64Content);

$dat[1] = str_replace(' ', '+', $dat[1]);
if (!($fileData = base64_decode($dat[1]))) {
    $response = new JsonResponse(
        array(
            'message' => "Base64 decoding error."
        ), 400);

    return $response;
}
$fileName = $entity->getUploadPath() . "/" . uniqid() . ".jpeg";

if (file_put_contents($fileName, $fileData)) {

    $entity->setPictureUrl($fileName);
    $em->persist($entity);
    $em->flush();

    return new JsonResponse(array('message' => 'Success!'), 200);
}

但是在上面的代码段中,$fileData无法访问。我看不出它是什么表明它不是假的。我的file_put_contents函数不起作用,并返回500错误。

错误:

  

http://localhost:8000/security/web/user/1/submit/image/无法加载资源:服务器响应状态为500(内部服务器错误)

dat[1]中的字符串如下:

/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAFoAhwMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAAAAgMEBQYHAf/EADsQAAIBAwIDBgMGBQIHAAAAAAECAwAEERIhBSIxBhMyQVFhFEJxI2KBkaGxFTNDUvAkwRY0U3KC0eH/xAAZAQADAQEBAAAAAAAAAAAAAAAAAQIDBAX/xAAiEQACAgEEAwADAAAAAAAAAAAAAQIRAxIhQVETMfAEsdH/2gAMAwEAAhEDEQA/AO40UUUAFFFFABRRUe4vbW2Gbi4hiH33AosCRRVFcdreCQ5HxqyMB0iUv+wqBddtoI8iDh12+M7y4jGwz5n0q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36+1QJuP8wbXlxpOtYBqyBjOpznPrSbfsndSD7R3+mcVb2fYwDqM/hWiwBXbKF+Lzz8i9664xiSUkYznGBgYr0rdtER3Melvl04B+u+f1rcWfZJExiM1cW3ZkbZjH41axJBS6OZWvDb6ZBEVxHnIUZAFaXhPA0t1Gq0j1f3Fa39p2fjTxqPyqxThEA+UflVKC6HZScDaSNdDDYdKK0sVjHH0UUVYifRRRTAKhcU4fDxK1NvPqCk5ypwam0UmlJUwOa8e7H2MBLW1vlv7nYsf1rP/APC0spwVAX0rrN+oLHIBqPEi58I/KpUIr0Nts5xb9iVJyUz+FWlt2MjX+kK38ar/AGj8qfAGeg6VVCMbbdk40+RR+FWMPZyJOorR4HpXtMCoi4LAnyj8qlJw+JOiipwrygBhbdF6KKcEajypdeUAeaR6V7RRQAUUedFAH//Z

Symfony可能会在file_put_contents

行上看到以下错误
Warning: file_put_contents(uploads/pictures/56c38912d5b4f.jpeg): failed to open stream: No such file or directory

是否需要写入文件夹的权限?因此它给出了一个错误coseguir,如果不存在它应该创建它时不打开文件?我如何授予此权限?

0 个答案:

没有答案