… you sure its finding the file you think it’s finding? (I’ma guess there’s a config.php file inside the directory of your main page.)
include/require is not “oh go run this code out in this page and get me the results/functions/variables”, it’s “copy and paste the code in that file in here, then keep going.”
Your function can see only three types of variables:
1- Those which were defined in the function body (local variables);
function myFunc() {
$foo = 'bar';
echo $foo;
}
2- Those which were defined outside the function and declared as global inside the function:
$foo = 'bar';
function myFunc() {
global $foo;
echo $foo;
}
3- Those which were passed to the function as arguments:
$foo = 'bar';
function myFunc($param){
echo $param;
}
myFunc($foo);
So, to make external variables visible by the function you should either declare them as global in the function body (that is a bad practice and not recommended usually) or pass them as arguments (standard practice).
Now that I think of it, it wouldn’t hurt to force the thumbnail to be a jpg (I dont want overly complicated thumbnails).
Here the page where I can upload an image
I want to make sure the user uploads a file of those for extensions, so I guess the if statement above is good, but I also want to make sure the uploaded image is lass than 1000K
Since I only want to use the inputs that are used, a foreach statement is in order (then an quick if statement to even see if that variable is being used
Is this ok?
foreach ($images as $image) {
if(empty($image)) {
//code to upload 1 image/create thumbnail
}
}
$image would never be empty - if a file is uploaded, that element simply doesnt exist, so the foreach will only operate on existing elements. Note that this is NOT the same behavior as a text box, but IS the same behavior as a checkbox.
Assuming $images is tied to $_FILES[‘images’], this would work.
Notice: Undefined index: name in /home/luke69/public_html/admin/insert_provider.php on line 153
Error: File too big ( < 500Kb) or wrong type (gif, jpg, bmp, or png)
(heres my foreach loop,
foreach ($_FILES['images'] as $image) {
$ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION));
if( (in_array($ext, ['jpg', 'jpeg', 'gif', 'png', 'bmp']) && ($image["size"] < 512000)) ){
$filename = $image['name'];
$source = $image['tmp_name'];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
} else {
echo "<p class='text-danger'><span class='glyphicon glyphicon-remove'></span> Error: File too big ( < 500Kb) or wrong type (gif, jpg, bmp, or png)</p>";
}
}
ok, fixed that so now when I fill out the form, I get a new error.
Warning: move_uploaded_file(…/providers/{dbh->lastInsertId()}/10429382_10152512724491223_7833921182302805412_n (1).jpg): failed to open stream: No such file or directory in /home/luke69/public_html/admin/insert_provider.php on line 160
Warning: move_uploaded_file(): Unable to move ‘/tmp/php2gzBkO’ to ‘…/providers/{dbh->lastInsertId()}/10429382_10152512724491223_7833921182302805412_n (1).jpg’ in /home/luke69/public_html/admin/insert_provider.php on line 160
You haven’t showed us the database calls preceding that statement in the code. If the database insert failed then that would explain why you cannot retrieve the id of that last insert.