Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 10-11-2022, 08:22 AM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Where do I edit this code?

So I have a working image upload php file, but its getting to the point where I need to start renaming the files being uploaded based on the date/time.

This is the code I currently have to upload the images:

Quote:
<?php
$target_dir = "uploads/";
$newFileName = $target_dir .'fileName'.'.'. pathinfo($_FILES["fileToUpload"]["name"] ,PATHINFO_EXTENSION);
$uploadOk = 1;
$imageFileType = pathinfo($_FILES["fileToUpload"]["name"] ,PATHINFO_EXTENSION);

if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}

if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}

if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}

if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newFileName)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";

} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
What I'd like to do is add something along the lines of:

Quote:
if(isset($_POST['sub'])){
if($_FILES['userImage']['name']){

$time = date("YmdHis")."-".time();

$fileName = $_FILES['userImage']['name'];
$fileName = $time."-".$fileName ;

move_uploaded_file($_FILES['userImage']['tmp_name'], "uploads/".$fileName);
$img="uploads/".$_FILES['userImage']['name'];

}else{
echo "Something went wrong";
}
}
But I cant figure out where I need to edit my original code, or append the date rename part, every time I try it stops uploading the image file to the server :/

Basically, what I need to be able to do is rename image.jpg to image10112022101656.jpg (which I beleive the $time = date("YmdHis")."-".time(); should be doing, I just can't figure out where to drop that new part of code into my original, any help would be appreciated.

Also, as a secondary question on the same subject, once the file is uploaded to the directory on the server, how would I go about submitting that url to a row in my SQL database and attaching it as an image to a specific recipe?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2022, 03:17 PM   #2
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
$newFileName = $target_dir .'fileName'.time().'.'. pathinfo($_FILES["fileToUpload"]["name"] ,PATHINFO_EXTENSION);

or...

$newFileName = $target_dir . time().'-fileName'.'.'. pathinfo($_FILES["fileToUpload"]["name"] ,PATHINFO_EXTENSION);
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2022, 03:26 PM   #3
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by Publisher Bucks View Post
Also, as a secondary question on the same subject, once the file is uploaded to the directory on the server, how would I go about submitting that url to a row in my SQL database and attaching it as an image to a specific recipe?
Depends on your logic and how you build your sql tables, but something along these lines...

else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newFileName)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
// add sql query here
INSERT INTO image_table (id, filename, recipe, ...)
VALUES ('', $newFileName, 'Fried titty', ...)
}

While you're at it, you might as well want to store the width and height of the image so you can add the width and height tags to your html output as well. After upload, you could also automatically create a thumbnail, as well as converting the image to webp (smaller in file size = good for seo).

Alternatively, you could move the uploaded image directly to a folder matching that recipe...
Could use the id of the recipe, or the name/slug (or hash) or whatever. Basically, creating a new folder for each new recipe in the database. Then in your recipe page, you can create a function to display images, which should then be located in that recipe folder with matching name.


I would consider such approach if you are planning on adding 1000s of recipes and thus, going to end up with one folder with a shit ton of image files.
During image upload, just check if the folder already exists or not, else go create it:
if (!is_dir('path/to/recipes/friedtitty')) mkdir(path/to/recipes/friedtitty', 0777, true);
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2022, 03:57 PM   #4
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by Publisher Bucks View Post
Also, as a secondary question on the same subject, once the file is uploaded to the directory on the server, how would I go about submitting that url to a row in my SQL database and attaching it as an image to a specific recipe?
Another really simple approach would be to rename your uploaded file to the same name of the title of the recipe. Then you can skip adding the image to a database entirely.

$recipe_title = "Salty Seamen Sauce";
$recipe_image = trim(str_replace(" ", "-", strtolower($recipe_title))) . "jpg";
// which would become salty-seamen-sauce.jpg
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2022, 10:54 PM   #5
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Awesome, thank you!

Also, as a side question, I'm seeing a ton of webp images as of late, whats the actual purpose of them? Is it purely for SEO(filesize) or do they serve a purpose other than that?

I only ask as you mentioned webp in your reply above lol
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-12-2022, 05:05 AM   #6
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by Publisher Bucks View Post
Awesome, thank you!

Also, as a side question, I'm seeing a ton of webp images as of late, whats the actual purpose of them? Is it purely for SEO(filesize) or do they serve a purpose other than that?

I only ask as you mentioned webp in your reply above lol
Well, not just SEO, since the file size is smaller, it will load faster which is a better user experience. 10 jpg images of 100kb each or 10 webp images of 55kb each, makes quite the difference in load time.

Serving large, non-optimized images is kind of a no go in 2022. You want to serve smaller images for mobile users compared to desktop sized images, use webp (with fallback if there's no browser support), lazyload the images below the fold.

These are somewhat the bare minimum things to do. You want your pages to load really fast these days, just optimizing images isn't even enough.

I would go much further and look at cache-ing a static, minified version of the recipe pages, cutting out all sql requests and php execution all together. But also using a PHP handler which supports Opcache (in-memory cache) etc.
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-13-2022, 02:37 AM   #7
Tjeezers
Webmaster
 
Tjeezers's Avatar
 
Industry Role:
Join Date: Mar 2007
Location: BP4L - NL/RO
Posts: 16,556
Quote:
Originally Posted by zijlstravideo View Post
Well, not just SEO, since the file size is smaller, it will load faster which is a better user experience. 10 jpg images of 100kb each or 10 webp images of 55kb each, makes quite the difference in load time.

Serving large, non-optimized images is kind of a no go in 2022. You want to serve smaller images for mobile users compared to desktop sized images, use webp (with fallback if there's no browser support), lazyload the images below the fold.

These are somewhat the bare minimum things to do. You want your pages to load really fast these days, just optimizing images isn't even enough.

I would go much further and look at cache-ing a static, minified version of the recipe pages, cutting out all sql requests and php execution all together. But also using a PHP handler which supports Opcache (in-memory cache) etc.
Sweet reply! very Helpful!
__________________
Enroll in the SWAG Affiliate Asian Live Cam Program and get 9 free quality linkbacks from my network!
Wanna see how old school I am? Look at this! All my Cam Review Sites are here!
Tjeezers is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
code, file, image, $filename, $_files[userimage][name];, dateymdhis.-.time;, $time, rename, server, original, figure, upload, uploaded, edit, specific, attaching, drop, beleive, recipe, image.jpg, database, image10112022101656.jpg, secondary, question, subject



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.