categories on upload php upload page
Hello I'm working on a project that has an upload page and in the background it uploads the pictures in dir /uploads/
and saves it to the user_images
table (the url) in my datebase.
So, I want to have a gallery with categories, but when they upload I need something like a dropdown menu
where they choose something like cars, houses, etc.
In my gallery I need to show the categories. I'm thinking like all the categories with id's.
When I submit, the table will be id and image_link, and in the gallery page I specify in this div that I want the images with id=x
.
Can someone help me with this? i'd be really happy! ps: sorry for my bad english
edit: i need it in with pdo Thanks again!
upload.php;
<center><form action="galleryupload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
</div>
galleryupload.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$target_file2 = "random-dir/";
$target_dir = "random-dir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO user_image (image_link) VALUES (:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
php mysql pdo
add a comment |
Hello I'm working on a project that has an upload page and in the background it uploads the pictures in dir /uploads/
and saves it to the user_images
table (the url) in my datebase.
So, I want to have a gallery with categories, but when they upload I need something like a dropdown menu
where they choose something like cars, houses, etc.
In my gallery I need to show the categories. I'm thinking like all the categories with id's.
When I submit, the table will be id and image_link, and in the gallery page I specify in this div that I want the images with id=x
.
Can someone help me with this? i'd be really happy! ps: sorry for my bad english
edit: i need it in with pdo Thanks again!
upload.php;
<center><form action="galleryupload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
</div>
galleryupload.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$target_file2 = "random-dir/";
$target_dir = "random-dir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO user_image (image_link) VALUES (:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
php mysql pdo
What isn't working as expected? What do you need help with?
– WillardSolutions
Nov 20 '18 at 20:49
I would add a column like 'category_id' for the category id's to the table 'user_image' and save the selected category in there. Then you can load all images by category (SELECT image_link FROM user_image WHERE category_id=123) where 123 is the id of the category you want to show. Is this what you are looking for?
– Marvin Klar
Nov 22 '18 at 23:11
add a comment |
Hello I'm working on a project that has an upload page and in the background it uploads the pictures in dir /uploads/
and saves it to the user_images
table (the url) in my datebase.
So, I want to have a gallery with categories, but when they upload I need something like a dropdown menu
where they choose something like cars, houses, etc.
In my gallery I need to show the categories. I'm thinking like all the categories with id's.
When I submit, the table will be id and image_link, and in the gallery page I specify in this div that I want the images with id=x
.
Can someone help me with this? i'd be really happy! ps: sorry for my bad english
edit: i need it in with pdo Thanks again!
upload.php;
<center><form action="galleryupload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
</div>
galleryupload.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$target_file2 = "random-dir/";
$target_dir = "random-dir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO user_image (image_link) VALUES (:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
php mysql pdo
Hello I'm working on a project that has an upload page and in the background it uploads the pictures in dir /uploads/
and saves it to the user_images
table (the url) in my datebase.
So, I want to have a gallery with categories, but when they upload I need something like a dropdown menu
where they choose something like cars, houses, etc.
In my gallery I need to show the categories. I'm thinking like all the categories with id's.
When I submit, the table will be id and image_link, and in the gallery page I specify in this div that I want the images with id=x
.
Can someone help me with this? i'd be really happy! ps: sorry for my bad english
edit: i need it in with pdo Thanks again!
upload.php;
<center><form action="galleryupload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
</div>
galleryupload.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$target_file2 = "random-dir/";
$target_dir = "random-dir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO user_image (image_link) VALUES (:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
php mysql pdo
php mysql pdo
edited Nov 20 '18 at 18:43


dustinos3
4491717
4491717
asked Nov 20 '18 at 18:31
phpislitxphpislitx
62
62
What isn't working as expected? What do you need help with?
– WillardSolutions
Nov 20 '18 at 20:49
I would add a column like 'category_id' for the category id's to the table 'user_image' and save the selected category in there. Then you can load all images by category (SELECT image_link FROM user_image WHERE category_id=123) where 123 is the id of the category you want to show. Is this what you are looking for?
– Marvin Klar
Nov 22 '18 at 23:11
add a comment |
What isn't working as expected? What do you need help with?
– WillardSolutions
Nov 20 '18 at 20:49
I would add a column like 'category_id' for the category id's to the table 'user_image' and save the selected category in there. Then you can load all images by category (SELECT image_link FROM user_image WHERE category_id=123) where 123 is the id of the category you want to show. Is this what you are looking for?
– Marvin Klar
Nov 22 '18 at 23:11
What isn't working as expected? What do you need help with?
– WillardSolutions
Nov 20 '18 at 20:49
What isn't working as expected? What do you need help with?
– WillardSolutions
Nov 20 '18 at 20:49
I would add a column like 'category_id' for the category id's to the table 'user_image' and save the selected category in there. Then you can load all images by category (SELECT image_link FROM user_image WHERE category_id=123) where 123 is the id of the category you want to show. Is this what you are looking for?
– Marvin Klar
Nov 22 '18 at 23:11
I would add a column like 'category_id' for the category id's to the table 'user_image' and save the selected category in there. Then you can load all images by category (SELECT image_link FROM user_image WHERE category_id=123) where 123 is the id of the category you want to show. Is this what you are looking for?
– Marvin Klar
Nov 22 '18 at 23:11
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399343%2fcategories-on-upload-php-upload-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399343%2fcategories-on-upload-php-upload-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What isn't working as expected? What do you need help with?
– WillardSolutions
Nov 20 '18 at 20:49
I would add a column like 'category_id' for the category id's to the table 'user_image' and save the selected category in there. Then you can load all images by category (SELECT image_link FROM user_image WHERE category_id=123) where 123 is the id of the category you want to show. Is this what you are looking for?
– Marvin Klar
Nov 22 '18 at 23:11