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?
Related
I'm trying to upload a photo using the following code. Suppose I'm uploading "abc.gif". It uploads in the proper directory as "abc.jpg". But my question is does the file type actually change?
$file_name = $_FILES['input_name']['name'];
$file_tmp =$_FILES['input_name']['tmp_name'];
move_uploaded_file($file_tmp, "abc.jpg");
This piece of code works perfectly while uploading.
But while making a resized copy of this abc.jpg using—
imagecreatefromjpg("abc.jpg") & imagejpeg()
—it shows a black screen.
When I move the file using the extension .jpg, does the file type actually change? Why does this problem occur?
Please verify the your imagecreatefromjpg("abc.jpg") & imagejpeg() function work correctly, you say file move successfully and display correctly so issue in the this image operation function which convert image into black image.
Thanks.
Well, I've uploaded an app to Heroku, and I've discovered that I can't upload files to it. Then I started to use Dropbox as storage option, and I've done a few tests, of send and retrieve link, and all worked fine.
Now, the problem is to use the uploadFile() method on DropboxAdapter. He accepts an resource as the file, and I did'nt work well. I've done a few tests, and still no way. Here is what I am doing, if anyone could me point a solution, or a direction to this problem, please. :)
Here is my actual code for the update user (Update the user image, and get the link to the file).
$input = $_FILES['picture'];
$inputName = $input['name'];
$image = imagecreatefromstring(file_get_contents($_FILES['picture']['tmp_name']));
Storage::disk('dropbox')->putStream('/avatars/' . $inputName, $image);
// $data = Storage::disk('dropbox')->getLink('/avatars/' . $inputName);
return dd($image);
In some tests, using fopen() into a file on the disk, and doing the same process, I've noticed this:
This is when I've used fopen() on a file stored on the public folder
http://i.imgur.com/07ZiZD5.png
And this, when i've die(var_dump()) the $image that I've tried to create. (Which is a suggestion from this two links: PHP temporary file upload not valid Image resource, Dropbox uploading within script.
http://i.imgur.com/pSv6l1k.png
Any Idea?
Try a simple fopen on the uploaded file:
$image = fopen($_FILES['picture']['tmp_name'], 'r');
https://www.php.net/manual/en/function.fopen.php
You don't need an image stream but just a filestream, which fopen provides.
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);
I am using plupload to upload file in my php based website, with large file uploading the file becomes a file named 'blob' without any suffix. I know this is a binary file that contains the raw data, question is how to retrieve the data and save it back as an image file, say .png/.jpg or etc? I tried:
$imageString = file_get_contents($blogPath);
$image = imagecreatefromstring($imageString);
But it gives me some 'Data is not in recognized format...' error, any thoughts? Thanks in advance.
Your call to imagecreatefromstring() should work just fine if your file_get_contents() is working. Use var_dump($imageString) to verify. Did you mean to name your variable $blobPath instead of $blogPath?
You don't need to load this image though. Just rename the file.
rename($blobPath, 'new/path/here.jpg');
http://php.net/manual/en/function.rename.php
I am storing the uploaded image files for late use, like attaching them to posts or products(my site is e-commerce CMS). I figured that my image file didn't get fully uploaded to the server, the image before upload is 6mb, but the blob file is just 192kb, so my best guess is that what get uploaded is just a chunk instead of the whole package, and yet that brought up another question: how should I take all the pieces and assemble them as one complete image file? As mentioned earlier, I am using plupload for js plugin and php as backend, the backend php code to handle uploading goes like this:
move_uploaded_file($_FILES["file"]["tmp_name"], $uploadFolder . $_FILES["file"]["name"]);
Instead of doing that you should do this to display image to the browser
<img src="data:image/jpeg;base64,'.base64_encode( $row['blob_image'] ).'"/>
I'm not sure what imagecreatefromsting does or how it encodes the image.
I looked at the documentation for that function; you're missing:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data); <--- this operation
CodeIgniter upload library only supports uploading image file from PC.
I am trying to make a code that a user can upload image with image url address.
http://example.com/photo/jake2910.jpg
I simply send this image address to server and upload the photo.
Is there a way to do that? (trust me I tried different codes already for few days.)
There is no need in CI's upload library at all. You can simply download the file with this code:
$url = 'http://example.com/photo/jake2910.jpg';
/* Extract the filename */
$filename = substr($url, strrpos($url, '/') + 1);
/* Save file wherever you want */
file_put_contents('upload/'.$filename, file_get_contents($url));
But be very cautious about what files you are trying to save. Remember that even images can be stuffed with vulnerable code.
Try this
copy('http://example.com/photo/jake2910.jpg', '/mylocation/jake2910.jpg');
for more details you can check this similar post
Copy Image from Remote Server Over HTTP