gpt4 book ai didi

php图像处理帮助或类?

转载 作者:行者123 更新时间:2023-11-29 06:20:28 25 4
gpt4 key购买 nike

我真的很难尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com