如何在 modx Revolution 中上传图像而不重新加载页面

发布于 2024-12-26 10:16:23 字数 120 浏览 1 评论 0原文

如何在 Web 上下文(前端)中上传图像,而无需在 modx Revolution 中重新加载页面?我正在尝试使用 fileupload extra 来上传图像,但它正在重新加载页面。有人可以帮我吗?

How to upload images in web context (frontend) without reloading the page in modx revolution? I am trying to use fileupload extra for uploading images but it is reloading the page. Can anyone help me, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2025-01-02 10:16:23

终于我得到了答案。我们可以通过使用简单的 php 代码和一个小的 javascript 来完成此操作,而无需使用 FILEUPLOAD 插件。
php 代码:-

<?php

$path = "uploads/";

$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024)) // Image size max 1 MB
{
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{

echo "image uploaded";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}

对于其他 javascript 和所有你可以参考以下链接:-
http://www.9lessons.info/2011/08 /ajax-image-upload-without-refreshing.html

finally i got the answer. we can do it without using FILEUPLOAD addon by using the simple php code and a small javascript..
php code:-

<?php

$path = "uploads/";

$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024)) // Image size max 1 MB
{
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{

echo "image uploaded";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}

for other javascript and all u can refer the below link:-
http://www.9lessons.info/2011/08/ajax-image-upload-without-refreshing.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文