php图像处理帮助或类?

标签 php mysql image

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

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

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

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

最佳答案

这里有一些来 self 的 Zend Framework Controller 的灵感!也许还没有达到生产质量,但它已经完成了工作。

   $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;
    }

关于php图像处理帮助或类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4000252/

相关文章:

ios - 使用远超出预期范围的组件值创建的图形、UIColor

android - 加载较小分辨率的图像,直到较大分辨率的图像完成下载

iphone - 将 UIView 的表示保存到文件

javascript - 使用 JCombo 制作链式组合框

php - 保护通过电子邮件发送的delete.php链接

php - 数字和 CSS 类

php - 为什么 "?[^a-z\-\+]hit[^a-z\-\+]"与 "hit"不匹配(第一个字符没有空格?)

java - 无法从 java 连接到 mysql。 mysql在另一个系统中

c# - 使用多个参数选择返回mysql语法错误

php - Mysql 没有返回错误,但没有给出任何结果,但在 phpmyadmin 中它返回