首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php图像操作帮助还是类?

问php图像操作帮助还是类?
EN

Stack Overflow用户
提问于 2010-10-23 03:24:51
回答 2查看 142关注 0票数 0

我真的很难尝试使用php和mysql上传图片,我真的需要帮助!

这就是我想用自然语言做的事情:

代码语言:javascript
复制
1. upload an image
2. check if format is okay(png, jpeg, gif)
3. rename the image file, so theres no ambugity in this format(eg. pic-$userid.gif)

4. upload the pic to the images/folder
5. and delete the old one, or remove the defualt picture when on registration

我正在尝试在线查找资源,但似乎找不到任何资源!!1谢谢:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-10-23 03:32:00

如果你有耐心,我认为研究这些人的代码是最好的方法:http://www.verot.net/php_class_upload.htm

或者,为什么不直接使用他们的类。它会帮你从很多头痛中解脱出来,并帮助你更快地达到目标。

干杯!

票数 1
EN

Stack Overflow用户

发布于 2010-10-23 03:35:47

这里有一些来自我的Zend Framework控制器的灵感!也许还没有达到产品质量,但它已经完成了工作。

代码语言:javascript
复制
   $location = $uploadForm->attachment->getFileName();

    $image = new Imagick($location);
    $size = $image->getImageGeometry();
    $image->destroy();

    $attachment = new Collection_Model_Attachment();
    $attachment->memberId = Zend_Auth::getInstance()->getIdentity()->id;
    $attachment->mimeType = $uploadForm->attachment->getMimeType();
    $attachment->name = $uploadForm->attachment->getValue();
    $attachment->width = $size['width'];
    $attachment->height = $size['height'];
    $attachment->sha1sum = sha1_file($location);

    $attachmentMapper = new Collection_Model_AttachmentMapper();
    $attachmentMapper->post($attachment);

    $designAttachment = new Collection_Model_DesignAttachment();
    $designAttachment->designId = $design->id;
    $designAttachment->attachmentId = $attachment->id;

    $designAttachmentMapper = new Collection_Model_DesignAttachmentMapper();
    $designAttachmentMapper->post($designAttachment);

    // Set default photo
    if (!$design->attachmentId)
    {
      $design->attachmentId = $attachment->id;
      $this->_designMapper->put($design);
    }

    $attachmentDir =
      realpath(sprintf(
        '%s/../data/attachments/%02d',
        $_SERVER['DOCUMENT_ROOT'],
        (int)($attachment->id / 100)
      ));
    if (!file_exists($attachmentDir))
      mkdir($attachmentDir);
    $attachmentPath = sprintf('%s/%04d.jpg', $attachmentDir, $attachment->id);

    $success = rename($location, $attachmentPath);
    if (!$success)
    {
      // TODO: error handling
      echo "move_uploaded_file failed: [$location] -> [$attachmentPath]";
      $this->render('notfound');
      return;
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4000252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档