Reputation: 75
Now I am performing an image upload operation by dragging the image on the field and I successfully uploaded it to the destination. Now I need to upload the same image on the multiple folders while dragging the image to the field, the image should be inserted in multiple folders. The problem arises when I try to upload the same image on multiple folder, the image getting inserted on first folder and not in others. I have attached the code below.
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;
}
}
In the post_ads
folder the image is inserted but in other folders it isn't. Can any of you suggest me a possible solution?
Upvotes: 2
Views: 140
Reputation: 75
Thank you for your suggestion guys. I have found the exact and simple way for it.I have attached the code below
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;
}
}
Upvotes: 0
Reputation: 181
There are some good php libraries for handling uploads. i`m using http://www.verot.net/php_class_upload.htm it simplifies your job. you can upload files to multiple folders then like:
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');
//-----------------------------------------
}
So you can resize, resample and so on and then you call Process for the different folders how many times you want.
Upvotes: 0
Reputation: 61
move_uploaded_file will move the file, and not copy it -- which means it'll work only once.
If you are using copy, there shouldn't be any limit at all on the number of times you can copy : the temporay file created by the upload will only be destroyed at the end of the execution of your script (unless you move/delete it before, of course)
Still, maybe a solution would be to use move_uploaded_file first, and, then, copy ? A bit like that, I suppose :
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]);
}
Upvotes: 1