拖放图像并将其上传到多个文件夹
Drag drop image & upload it on multiple folder
现在我正在通过在字段上拖动图像来执行图像上传操作,并成功将其上传到目标。现在我需要在多个文件夹上上传相同的图像,同时将图像拖到字段中,图像应该插入多个文件夹中。当我尝试在多个文件夹上上传相同的图像时,就会出现问题,图像入到第一个文件夹中而不是其他文件夹中。我附上了下面的代码。
function uploadimage() {
$headerimage=array();
if (!empty($_FILES)) {
$headerimage[0] = 'uploadimages/post_ads'."/".$_FILES['file']['name'];
echo move_uploaded_file($_FILES['file']['tmp_name'],$headerimage[0]);
$headerimage[1] = 'uploadimages/latestimages'."/".$_FILES['file']['name'];
echo move_uploaded_file($_FILES['file']['tmp_name'],$headerimage[1]);
$headerimage[2] = 'uploadimages/listimages'."/".$_FILES['file']['name'];
echo move_uploaded_file($_FILES['file']['tmp_name'],$headerimage[2]);
$headerimage[3] = 'uploadimages/photoimages'."/".$_FILES['file']['name'];
//$headerpath = 'uploadimages/photoimages'."/".$_FILES['file']['name'];
echo move_uploaded_file($_FILES['file']['tmp_name'],$headerimage[3]);
$headerimage[4] = 'uploadimages/slideimages'."/".$_FILES['file']['name'];
//$headerpath = 'uploadimages/slideimages'."/".$_FILES['file']['name'];
echo move_uploaded_file($_FILES['file']['tmp_name'],$headerimage[4]);
print_r($headerimage);
$_SESSION['upload_images'][]=$headerimage;
}
}
在post_ads
文件夹中插入图像,但在其他文件夹中没有。你们中的任何人可以向我建议一个可能的解决方案吗?
move_uploaded_file将移动文件,而不是复制它 - 这意味着它只会工作一次。
如果您使用的是 copy,则复制的次数根本不应该有任何限制:上传创建的 temporay 文件只会在脚本执行结束时销毁(当然,除非您之前移动/删除它)
不过,也许解决方案是先使用move_uploaded_file,然后再复制?有点像,我想:
if (move_uploaded_file($_FILES['file']['tmp_name'],$headerimage[1])) {
copy($headerimage[1], $headerimage[2]);
copy($headerimage[1], $headerimage[3]);
copy($headerimage[1], $headerimage[4]);
}
有一些很好的 php 库来处理上传。 我正在使用 http://www.verot.net/php_class_upload.htm 它简化了您的工作。 您可以将文件上传到多个文件夹,然后像:
include('class.upload.php');
//--------------------------------------
$upload_handler = new Upload($_FILES['file']);
if ($upload_handler->uploaded)
{
$new name = time().rand(10000,99999);
//----------------------------------------
$upload_handler->image_convert = 'jpg';
$upload_handler->jpeg_quality = 70;
$upload_handler->image_background_color = '#FFFFFF';
$upload_handler->image_resize = true;
$upload_handler->file_new_name_body = $new name;
$upload_handler->image_ratio_fill = true;
$upload_handler->image_ratio_no_zoom_in = true;
$upload_handler->image_x = 900;
$upload_handler->image_y = 700;
$upload_handler->Process('folder_path_1');
//-----------------------------------------
$upload_handler->image_convert = 'jpg';
$upload_handler->jpeg_quality = 70;
$upload_handler->image_background_color = '#FFFFFF';
$upload_handler->image_resize = true;
$upload_handler->file_new_name_body = $new name;
$upload_handler->image_ratio_fill = true;
$upload_handler->image_ratio_no_zoom_in = true;
$upload_handler->image_x = 150;
$upload_handler->image_y = 150;
$upload_handler->Process('folder_path_2');
//-----------------------------------------
}
因此,您可以调整大小,重新采样等,然后根据需要为不同的文件夹调用Process多少次。
谢谢你们
的建议。我已经找到了准确而简单的方法。我附上了下面的代码
function uploadimage()
{
if (!empty($_FILES)) {
$headerimage= 'uploadimages/featuredimages'."/".$_FILES['file']['name'];
$headerimage1= 'uploadimages/latestimages'."/".$_FILES['file']['name'];
$headerimage2 = 'uploadimages/listimages'."/".$_FILES['file']['name'];
$headerimage3 = 'uploadimages/photoimages'."/".$_FILES['file']['name'];
$headerimage4 = 'uploadimages/slideimages'."/".$_FILES['file']['name'];
$headerimage5 = 'uploadimages/galleryimages'."/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$headerimage);
copy($headerimage, $headerimage1 );
copy($headerimage1, $headerimage2 );
copy($headerimage1, $headerimage3 );
copy($headerimage1,$headerimage4 );
copy($headerimage1,$headerimage5 );
$_SESSION['upload_images'][]=$headerimage1;
}
}
相关文章:
- 如何将乳胶配方奶粉图像保存到Asp.net中的文件夹中
- 在ng重复循环中显示来自不同文件夹的图像
- 如何通过资产管道提供Javascript中子文件夹中的图像
- 可在多个相册文件夹中查找的动态图像库
- 如何使用javascript从文件夹中获取图像并发布直接链接
- Yii2从js脚本的页面上添加来自供应商文件夹的图像、css、js文件
- 如何在PHP中使用url保护我的图像和文件夹免受直接访问
- 使用文件夹路径名保存所有图像文件和文件名
- 将图像输出到浏览器,然后再将其保存到文件夹
- jQuery:用文件夹中的图像填充数组.或者使用AJAX从文件夹加载图像
- 将样式表、javascript和图像分离到不同文件夹中的优势
- 使用javascript从磁盘中的文件夹中选择所有图像的路径
- 如何从本地文件夹(磁盘存储)读取或获取图像文件,并使用nodejs服务器将其发送到Angularjs
- Dropzone.js没有将图像上传到文件夹
- 如何使用javascript获取文件夹中的图像列表
- 将文件夹中的所有图像包括在阵列中的最佳方式是什么
- Android 引用 JavaScript 文件中的资产文件夹图像
- jQuery日期选择器上一个和下一个按钮没有显示,如何指向css中的主题文件夹图像
- 我如何读取文件夹图像和显示html内
- 在Canvas中循环遍历文件夹图像