I want to know that how can I overwrite images when they uploaded to server in php. For example I uploaded a photo to a folder as soon as I upload another image it will take place of previous image. Image name is not same it may differ. Thanks
Delete the previous image before uploading the new one using:
$path = $_SERVER['DOCUMENT_ROOT'].'img/img.jpg';
unlink($path);
This code basically assigns the path of the image to $path and deletes the image using unlink($path);
Related
I have absolute path of my uploaded image file and i want to get image file which i uploaded in my folder. So how can i get image file and how i can upload image.So i can perform image operation like watermark and rotate. So i have to get image file in code igniter.
i tried but it is not working
$upld_file = 'my absolute path';
$real_path = realpath($upld_file);
$img = base64_encode($real_path);
and i send $img parameter to upload image
I am getting "you did not select a file to upload"
C:\wamp64\www\codeigniter_project\assets/images/1551892667300.jpeg
This is my absolute path of my image
Thank You.
You don't need to get the absolute path of the image if you are storing the images inside a assets in the root of your project directory, You can access the image like this
echo base_url('assets/images/1551892667300.jpeg');
NOTE : you need to load the url helper first
You can try like this..
//define image path
$filename="C:/wamp64/www/codeigniter_project/assets/images/1551892667300.jpeg";
// Load the image
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, 90, 0);
//and save it on your server...
imagejpeg($rotate, "savedestinationpath.jpg");
That should be the file input name. eg: If your file browse input name is myFileInput then it should be $this->upload->do_upload('myFileInput')
Also make sure that you have set attribute enctype="multipart/form-data" for your form.
One nice example is here
I was looking for a good image upload plugin for CakePHP2 and found these ones:
https://github.com/angelitomg/QimageComponent
https://github.com/BradCrumb/CakeImageCropResize (my preference)
Both image uploads needs a $imagePath and a potential options array. Am I right that $imagePath should always be a path to an image on the server? Why can't it be the temporary image path (e.g. C:\xampp\tmp\php8454.tmp)?
I am trying to copy a resampled image. Something seems not working:
copy($_FILES['image']['name'],'logo.png');
$dir_subida = 'C:\xampp5\htdocs\bild';
$source = imagecreatefrompng($_FILES['image']['name']);
$destination = imagecreatefrompng($dir_subida . '\\logo.png');
imagecopyresampled($destination,$source,0,0,0,0,110,55,600,220);
First I copy the image and save it in a directory. Then, I define the source (an image that I am uploading in a form). Then I define the destination.
Then I try to resample and copy it with the default function imagecopyresampled.
It just copies the image right away without any kind of changes.
Am I missing something?
You must save the destination image to a file after you manipulate it.
imagepng($destination, 'c:\\path\\to\\file.png');
I have an image uploading script which works fine when uploading an image to the domain it's on, but I also need to upload the same image to an alternate subdomain.
Here's the bit of the code I'm having trouble with.
$filename = "../../images/home-features/" . $imagename;
$filename2 = "/var/www/vhosts/domain.org/httpdocs/images_home/features/" . $imagename;
imagejpeg($tmp,$filename,60);
imagejpeg($tmp,$filename2,60);
It's the second of the two which is not uploading. I don't get any errors - it's as if it has worked but then the image is not there.
Any ideas?
i dont know exactly why the second image isnt coming through the same resource. maybe the resource needs rewinding/resetting.
But WHY let the server do the same work all over again? Just copy the first file as the second!
copy($filename, $filename2);
ps. did you check the directory for the second file is writable?
I am working on an upload script that also resizes/rescales an image.
Currently it is working by uploading the image, moving to the upload dir (site.com/upload) and then resizing, and afterwards deleting the original again...
Now my question is:
Can I do this without moving the original to the upload dir and even better, also keeping the new file in tmp so I the user can afterwards confirm the image (so If they don't want it and just hit the 'back' button it won't stay in the upload dir.)
Current code:
move_uploaded_file($_FILES['file']['tmp_name'], 'resize-upload/'.$_FILES['file']['name']);
$filename=$_FILES['file']['name'];
$Imagick=new Imagick();
$Imagick-> readImage('resize-upload/'.$filename);
$Imagick-> scaleImage(200,200,auto);
$Imagick-> writeImage('resize-upload/resized-'.$filename);
unlink('resize-upload/'.$filename);
You can't. You don't have the access to the image if you haven't moved it yet. But you can generate more than one thumbnail at a time from same image/object and if you are storing/keeping the original also then you don't need to unlink it either.
Another way would be to use flash and resize the image on the client side and then only save the resized image.