Comments (20)
This is strange ... let me check. Also can I see your code?
from bulletproof.
I'm not getting this error.
from bulletproof.
This is my code running on Xampp 7.x on Fedora
<?php
require 'database_connect.php';
$image = new Bulletproof\Image($_FILES);
$imageName= base64_encode($_SESSION['admin_email']);
$image->setName($imageName)
->setMime(array('jpeg', 'gif', 'png', 'jpg'))
->setLocation(__DIR__ . "/avatars");
if (isset($_POST['submit'])){
$image->setDimension(128,128);
if($image["pictures"]){
// set the max width/height limit of images to upload (limit in pixels)
// pass name (and optional chmod) to create folder for storage
$upload = $image->upload();
if($upload){
$photo = $upload->getFullPath(); // uploads/cat.gif
}else{
$photo = NULL;
}
}
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$db->user[$_SESSION['admin_id']] = [
'firstName' => $fname,
'lastName' => $lname,
'email' => $email,
'photo' => $photo
];
}
/* header("Location:profile.php");
exit; */
?>
I tried to remove setName altogether, didn't work
Please forgive my mess, I'm trying to upload a photo, then I'll clean it. getFullPath returns empty, upon checking why I receive this error. I'm using version 3.0.2.
also another error with setDimentions, I cannot do
$image->setName($imageName)
->setMime(array('jpeg', 'gif', 'png', 'jpg'))
->setLocation(__DIR__ . "/avatars")
->setDimension(128,28);
it gives something like error boolean function, something like that forgot the error
from bulletproof.
Okay, at first glance this I was able to spot the issue. $_POST
and $_FILES
are two different arrays. One checked for posts made via your form (ex, text inputs) and the other $_FILES
checks for file uploads. So, it is correct to see "undefined index tmp_name`... error, because you are not checking if form is submitted.
Anyway, I can't be sure right now because I am trying to find a fix to resolve the error that appears when the browser blocks the image upload due to max file constraint. If you leave that from your HTML it might work nicely, until I find a solution. For now, I was able to try this script, which is slightly modified version of your and it works as intended:
require __DIR__ . '/src/bulletproof.php';
$image = new Bulletproof\Image($_FILES);
$imageName = rand(1, 100) . '-foo';
$image->setName($imageName)
->setMime(array('jpeg', 'gif', 'png', 'jpg'))
->setLocation(__DIR__ . "/avatars")
->setDimension(128,128);
if($image["pictures"]){
$upload = $image->upload();
if($upload){
$photo = $upload->getFullPath(); // uploads/cat.gif
// store in db
}else{
echo "error while uploading " . $image['error'];
$photo = NULL;
}
}else{
if($image['error']){
var_dump($image['error']);
}
}
Let me know if you have any more questions
from bulletproof.
Also make sure your HTML form element has the multiplart/form-data attribute eg: <form method="POST" enctype="multipart/form-data">
from bulletproof.
I just tried your code as is
$image->setName($imageName)
->setMime(array('jpeg', 'gif', 'png', 'jpg'))
->setLocation(__DIR__ . "/avatars")
->setDimension(128,128);
And the dimension error i was talking about showed up
Fatal error: Uncaught Error: Call to a member function setDimension() on boolean in /opt/lampp/htdocs/web/emall/production/app/profile_ctrl.php:11 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/web/emall/production/app/profile_ctrl.php on line 11
from bulletproof.
Well, maybe that is the issue. setLocation
method can only return false
(boolean) only if it failed to create a dir so, maybe you have no permission. In which case, you'll be able to capture the using your $image['error']
method
from bulletproof.
now it works, is it possible to resize the image?
from bulletproof.
Yes, just include one of the functions in the folder /utils which is for resizing images. They should work better than the actual bulletproof library
from bulletproof.
perfect thank you, since setDimensions is annoying, better to resize it if it doesn't fit. That's why setdimensions was giving me errors, I thought it automatically resize. My bad :)
from bulletproof.
One last question, if I let it do the naming automatically, can it guarantee unique names?
from bulletproof.
Yes, it will generate unique name always. Also setDimention method is for setting a limit of image width/height not resizing
from bulletproof.
I'm uploading like this
$photo = $upload->getName() . '.' . $upload->getMime();
and displaying like this, once they get to the db, since I cannot store getFullpath()
$path = 'avatars/';
$avatar =$path . $user->photo;
Is there a way to get the relative path? I mean is there a method I didn't use in your library that makes me write less code? it's nothing I know but when I saw getFullPath I started wondering about getRelativePath or similar
from bulletproof.
getFullPath()
will return the path starting from where the image is stored in ex: if you upload in images:
$image->setLocation(__DIR__ . '/images')
you will get the current path plus the full path before. If you want want to get only the relative path I think you should set the location as $image->setLocation('images')
from bulletproof.
I can't get the image from
<input type="file" name="data[photo]" id="photo" class="custom-file-input">
it always gives an undefined variable, I tried the script above and some other variations nothing worked
from bulletproof.
I think that may be because you are trying to upload multiple files. I haven't implemented that yet. You can just do a php foreach() and use the upload method to upload the images for now. Let me know if you are facing some issues to upload a single file
from bulletproof.
I'm just uploading one file, here's the latest variation I tried
<? require('common/session.php');
require "common/vendor/samayo/bulletproof/src/utils/func.image-resize.php";
$image = new Bulletproof\Image($_FILES);
if (isset($_POST['submit'])){
$image->setMime(array('jpeg', 'gif', 'png', 'jpg'))
->setLocation(__DIR__ . "/avatars");
if($image[$data["photo"]]){
$upload = $image->upload();
if($upload){
$resize = Bulletproof\resize(
$image->getFullPath(),
$image->getMime(),
$image->getWidth(),
$image->getHeight(),
120,
120
);
$data['photo'] = $upload->getName() . '.' . $upload->getMime();
}else{
echo "error while uploading " . $image['error'];
$data['photo'] = NULL;
}
} else{
if($image['error']){
var_dump($image['error']);
}
}
/* $data = array($_POST['data']);
$db->user->insert()
->data($data)
->run(); */
echo $data['photo'];
}
I tried many other things, this is my second project using your library, the first one worked, but now I had to use array since I have a billion input fields. faster to insert them like that
from bulletproof.
problem fixed
from bulletproof.
How did you fix it? I was just about to try it after work .. sorry
from bulletproof.
not really fixed, i thought it was but not really
https://stackoverflow.com/questions/46851647/cannot-insert-input-type-file-to-array-of-html-names
I don't know why SO votes down a question if it's hard to answer, anyhow I just discovered that you cannot add file input to html name array. unless you have a solution, I'd just add it to the array using php
from bulletproof.
Related Issues (20)
- iphone upload HOT 2
- How to delete existing (old) file while update? HOT 8
- Minor improvements HOT 2
- Packagist version outdated? Util functions not found thru namespace? And other bugs. HOT 2
- How do i upload multiple image, rename and create thumbnail HOT 4
- File upload not working in linux server HOT 2
- How to Save in JPG (instead of JPEG)? HOT 4
- Svg upload ? HOT 2
- Bulletproof - change image that was uploaded HOT 9
- Upsizing not working HOT 7
- Error! directory 'bulletproof' could not be created
- Readme examples are referencing wrong methods (setLocation is now setStorage ) HOT 4
- Uploading Image From a URL HOT 1
- The README.md shows "setLocation" as a valid function, when said function has appearently been renamed to "setStorage" HOT 1
- Dependency Dashboard
- Constant 'FILTER_SANITIZE_STRING' is deprecated HOT 2
- setName fails to work... HOT 1
- Image format error HOT 9
- Object of class UnwindExit could not be converted to string HOT 3
- PHP Deprecated: Return type of Bulletproof\Image HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bulletproof.