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 02-06-2022, 11:24 AM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,188
Image rename upon upload of duplicate file name?

Quote:
// Check if file already exists
if (file_exists($target_file)) {
//echo "Sorry, file already exists.";
//$uploadOk = 0;
rename($target_file, 'your_new_filename');
}
This is working however, its not creating a clickable image when I browse the image upload directory, could anyone point me in the right direction about how to get it to rename AND be a valid clickable image please when viewed in the directory itself?

I've tried this, which i thought would work but didnt:

[quote]
$imageFileType rename(2.'$imageFileType');
[quote]

__________________
Extreme Link List - v1.0
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-06-2022, 12:01 PM   #2
Klen
 
Klen's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
Quote:
Originally Posted by Publisher Bucks View Post
This is working however, its not creating a clickable image when I browse the image upload directory, could anyone point me in the right direction about how to get it to rename AND be a valid clickable image please when viewed in the directory itself?

I've tried this, which i thought would work but didnt:



No clue, i would simply rather exec linux command instead using PHP replacement for it, as those replacement would not work always, plus linux commands give far more options. Could be some permission problem.
Klen is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-06-2022, 12:19 PM   #3
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
1. Rename all files on upload for security, control and so you don't get dupes in the first place.

2. No idea about the clickable thing, since as usual you don't explain things properly.

How are you viewing it, in a directory index listing, hrefs, img src, something else?
__________________
__________________
ZTT is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-06-2022, 05:14 PM   #4
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,188
Quote:
Originally Posted by ZTT View Post
1. Rename all files on upload for security, control and so you don't get dupes in the first place.
Thats not an option unfortunately.

Quote:
2. No idea about the clickable thing, since as usual you don't explain things properly.
Its a directory index list, you click on a filename, it doesnt work as there is no file extension on the renamed image, my bad.
__________________
Extreme Link List - v1.0
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2022, 01:56 AM   #5
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
What about just prepending uniqid() to the start or end of the existing filename?
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2022, 02:11 AM   #6
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
Quote:
Originally Posted by Publisher Bucks View Post
Thats not an option unfortunately.
Why? If you're having to rename files if they exist, it can't be that important for them to strictly match the original name.

The files are effectively renamed when you upload anyway, when they're in the tmp directory, and when you move them from tmp you're 'renaming' them back to the original name, so instead you just pick a new unique name that you control that won't clash.

Anyway, if there's still some reason you can't do that, here's a basic code illustrating renaming of an uploaded file only if it exists. Save it as a PHP file and try it. Obviously change $up_dir to whatever you're using.


Code:
<?php
    $up_dir = 'upload/';
    $tmp_name = $_FILES["image"]["tmp_name"];
    $name = basename($_FILES["image"]["name"]);

    if (file_exists($up_dir.$name)) {
        // rename file however you like, eg:
        $name = $name.'_'.time();
    }

    move_uploaded_file($tmp_name, $up_dir.$name);
?>

<form enctype="multipart/form-data" action="" method="post">
    <input type="file" name="image">
    <input type="submit" value="Upload">
</form>
__________________
__________________
ZTT 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
image, file, clickable, directory, [quote], rename, upload, direction, viewed, $imagefiletype, helpme, rename2.$imagefiletype;, valid, browse, //echo, file_exists$target_file, exists.;, //$uploadok, exists, check, duplicate, creating, rename$target_file, your_new_filename;



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.