首页 \ 问答 \ 关于生物lw24

关于生物lw24

请写出过程
更新时间:2023-07-16 07:07

最满意答案

你的逻辑错了。

试试这段代码:

<?php

// src/AppBundle/Controller/ProductController.php
namespace Upload\FileBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Upload\FileBundle\Entity\Product;
use Upload\FileBundle\Form\ProductType;
use Symfony\Component\Form\FormView;


class ProductController extends Controller
{
    /**
     * @Route("/product/new", name="app_product_new")
     */
    public function newAction(Request $request)
    {
        $product = new Product();
        $form = $this->createForm(new ProductType(), $product);
        if ($request->isMethod(Request::POST))
        {
            $form->handleRequest($request);
            if ($form->isValid()) {
                // $file stores the uploaded PDF file

                $file = $product->getBrochure();
                /* @var Symfony\Component\HttpFoundation\File\UploadedFile $file */

                // Generate a unique name for the file before saving it
                $fileName = md5(uniqid()).'.'.$file->guessExtension();

                // Move the file to the directory where brochures are stored
                $brochuresDir = $this->container->getParameter('kernel.root_dir').'/../web/uploads/brochures';
                $file->move($brochuresDir, $fileName);

                // Update the 'brochure' property to store the PDF file name
                // instead of its contents
                $product->setBrochure($fileName);
               // ... persist the $product variable or any other work
                $em = $this->getDoctrine()->getManager();
                $em->persist($product);
                $em->flush();
                return $this->redirect($this->generateUrl('app_product_list'));
            }
        }



        return $this->render('UploadFileBundle:Product:new.html.twig', array(
            'form' => $form->createView(),
        ));
    }

}

我还建议使用VichUploaderBundle https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md


Your logic is wrong.

Try this code:

<?php

// src/AppBundle/Controller/ProductController.php
namespace Upload\FileBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Upload\FileBundle\Entity\Product;
use Upload\FileBundle\Form\ProductType;
use Symfony\Component\Form\FormView;


class ProductController extends Controller
{
    /**
     * @Route("/product/new", name="app_product_new")
     */
    public function newAction(Request $request)
    {
        $product = new Product();
        $form = $this->createForm(new ProductType(), $product);
        if ($request->isMethod(Request::POST))
        {
            $form->handleRequest($request);
            if ($form->isValid()) {
                // $file stores the uploaded PDF file

                $file = $product->getBrochure();
                /* @var Symfony\Component\HttpFoundation\File\UploadedFile $file */

                // Generate a unique name for the file before saving it
                $fileName = md5(uniqid()).'.'.$file->guessExtension();

                // Move the file to the directory where brochures are stored
                $brochuresDir = $this->container->getParameter('kernel.root_dir').'/../web/uploads/brochures';
                $file->move($brochuresDir, $fileName);

                // Update the 'brochure' property to store the PDF file name
                // instead of its contents
                $product->setBrochure($fileName);
               // ... persist the $product variable or any other work
                $em = $this->getDoctrine()->getManager();
                $em->persist($product);
                $em->flush();
                return $this->redirect($this->generateUrl('app_product_list'));
            }
        }



        return $this->render('UploadFileBundle:Product:new.html.twig', array(
            'form' => $form->createView(),
        ));
    }

}

I also recommend using VichUploaderBundle https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md

相关问答

更多
  • 你的逻辑错了。 试试这段代码:
  • 换线: mysqli_query($conn,"[...]"); 成: $result = mysqli_query($conn,"[...]"); 然后检查: if ($result) { echo "success!"; } 因为: 返回值 失败时返回FALSE。 对于成功的SELECT,SHOW,DESCRIBE或EXPLAIN查询,mysqli_query()将返回一个mysqli_result对象。 对于其他成功的查询,mysqli_query()将返回TRUE。 资源 Change l ...
  • 确认密钥的格式和有效性的唯一可靠方法是使用它们执行操作。 使用EC2 API做一些简单的事情,在将它们存储到数据库之前需要所有三个因素。 请注意, 请确保您正确保护此数据库。 如果它被泄露,那么将存储凭证的AWS账户也将如此。 The only reliable way to confirm not only the format, but also the validity of the keys, is to perform an operation using them. Do something s ...
  • 看看这个教程: http : //wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/ take a look at this tutorial: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/
  • 您的代码容易受到SQL注入攻击 你需要传递参数$_POST['post_breakdowndate']而不是$_POST[post_breakdowndate] 您需要将查询更新为 mysqli_query($connect,"INSERT INTO posts (user, breakdowndate, policyinception, customername, customersurname, covertype, vehiclemake, vehiclemodel, vehiclereg, vehi ...
  • 你没有在你的活动中初始化context ,因此你将一个null上下文传递给你的MyDbHelper 。 当你从一个Activity(它扩展了Context )调用的时候,试试这个: myDbHelper = new MyDbHelper(this); You're not initialising context in your activity, therefore you're passing a null context into your MyDbHelper. As you're calling ...
  • 不要绑定参数,请尝试以下方法: $sql = ("INSERT INTO members (username, email, first_name, last_name, country, password_1) VALUES (:username, :email, $first_name, :last_name, :country, :password_1)"); $stmt = $mysqli->prepare($sql) or die("Failed Execution");; $stmt->ex ...
  • 从左侧面板插入数据后,只需调用一个包含代码的函数,即使用新文本设置更新数据 lab1.setText($first_name); .. .. 然后把$first_name放到 null I found the code I was looking for. This clears the addressBook panel, then I can pull my info from the database again. addressBook.removeAll(); addressB ...
  • 好吧,PDO只适用于初学者手册的基本案例。 无论什么复杂的问题都会给PDO带来麻烦以及任何其他API。 但是只要你准备好浪费你的时间编写大量的插入语句,在这里回答所有这些答案之后重复每个变量六到十次 - PDO是可以的。 但只是为了让您知道,标识符没有准备好的声明。 至于CKEditor - 它不是客户端应用程序吗? 如果是这样,它将保护任何东西。 所以,更好地遵循另一个答案的建议 - 在HTML页面上显示时通过htmlspecialchars()传递不受信任的用户输入 Well, PDO is okay ...
  • 我检查了你的代码。 Error : 1.) It was in select Query : placed extra ')' right parenthesis. 2.) It was in Insert Query : spelling of password was passsword. 更新:只需更改下面的查询。 $query = "SELECT * FROM `student` WHERE email='$_POST[userEmail]'"; $query = "INSERT INTO s ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)