Bradley99 Posted July 3, 2011 Share Posted July 3, 2011 I have an Image Hosting website, pretty simple script, when an image is uploaded, it goes into website.com/x!/imagename.jpg. I would like to encrypt/randomize the image name at the end of the link. Anyway to do this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/241021-encryptionrandom-link-ending/ Share on other sites More sharing options...
mikesta707 Posted July 3, 2011 Share Posted July 3, 2011 You could do a few things. One thing is you could use the current timestamp as the image name. That would make duplicates almost impossible. You could also take an MD5 hash of the file name, though you could run into the same file names unless you use a unique salt with every hash. You could easily just use a randomized string, or the current time stamp as the salt. Of course if you can do MD5, you can also use Sha1 or any other hashing or encrypting technique. Quote Link to comment https://forums.phpfreaks.com/topic/241021-encryptionrandom-link-ending/#findComment-1238002 Share on other sites More sharing options...
Bradley99 Posted July 3, 2011 Author Share Posted July 3, 2011 How would i use the timestamp? Or the easiest way? It's nothing major so don't want to spend too much time doing it. Code below // App define('APP_NAME', 'Hosting Mall'); // Your image hosting name define('TAG_LINE', 'Image Hosting For Everyone'); // Your tagline (for doctitles and logo) define('DESCRIPTION', 'Free Image Hosting Worldwide'); // For meta description define('KEYWORDS', 'images, photos, image hosting, photo hosting, free image hosting'); // For meta keywords // Folders /* If you change this, you also must change the folders name. */ define('DIR_UP','up/'); define('DIR_IM','x!/'); // Change this to have something like /X/filename.jpg - where "X/" is the folder name. define('DIR_WORKING',DIR_UP.'working/'); define('DIR_TEMP',DIR_UP.'temp/'); define('DIR_TH','thumbs/'); // Min-Max values -> php.ini rules the nation... $max_mb = '2'; // Max. image size (Mbytes) $max_by = $max_mb*1048576; // (bytes) $max_name = '10'; // Max. file name lenght. // Thumbs $mini_ancho = '150'; // Thumb width (pixels) $mini_alto = '150'; // Thumb height (pixels) // Resize $lowres = '16'; // Min. resize value (pixels) $higres = '1280'; // Max. resize value (pixels) // Options $lim_act = true; // true: Allows uploading just for your domain - false: Allows upload from anywhere (post from another website) $debug_mode = false; // false: Debug OFF - true: Debug ON. $cut_url = true; // true: Short URLs (TinyURL tr.im etc.) - false: normal url (http://mysite.com/images/image.jpg). $cut_url_service = 'tinyurl'; // tinyurl $cut_url_user = true; // If $cut_url = true -> true: Allows your users to cut their urls (preference) - false: Users can't choose to cut or not. $allow_over_resize = false; // true: Allows over resize images - false: Don't allow over resize. Quote Link to comment https://forums.phpfreaks.com/topic/241021-encryptionrandom-link-ending/#findComment-1238007 Share on other sites More sharing options...
mikesta707 Posted July 3, 2011 Share Posted July 3, 2011 well that isnt an upload script.. just seems to be some variables you are defining, but in the upload script you simply set the name of the uploaded file as th current time stamp, which can be gotten via the time() function. so for example $filename = time(); //proceed with move_uploaded_file() function, using the filename above //in your case, you probably have a directory included in the file name //so it may be something like $filename = "x!/".time(); Quote Link to comment https://forums.phpfreaks.com/topic/241021-encryptionrandom-link-ending/#findComment-1238009 Share on other sites More sharing options...
Bradley99 Posted July 3, 2011 Author Share Posted July 3, 2011 Posted wrong script, isit something to do with this? function ImageCreateFromBmp($filename) { /*** create a temp file ***/ $tmp_name = tempnam("/tmp", "GD"); /*** convert to gd ***/ if(bmp2gd($filename, $tmp_name)) { /*** create new image ***/ $img = imagecreatefromgd($tmp_name); /*** remove temp file ***/ unlink($tmp_name); /*** return the image ***/ return $img; } return false; } $bmp_img = ImageCreateFromBmp($handlework); unlink($handlework); $bmp2png = DIR_WORKING.substr($tmp_name, 0, -3).'png'; imagepng($bmp_img, $bmp2png); unset($handlework); $handlework = $bmp2png; unset($exten); $exten = 'png'; } Quote Link to comment https://forums.phpfreaks.com/topic/241021-encryptionrandom-link-ending/#findComment-1238011 Share on other sites More sharing options...
mikesta707 Posted July 3, 2011 Share Posted July 3, 2011 Do you not know your own script? Because I certainly don't.. So I can only guess. I don't know when that function is used, nor how it is used or if it is even used at all. If it is, then it seems you just have to set $handwork to the current timestamp (You may also need to concatenate the correct extension. However, this is just a guess as I've said. I don't know your code, and am unfamiliar with the bmp2gd class/library/whatever it is either. Quote Link to comment https://forums.phpfreaks.com/topic/241021-encryptionrandom-link-ending/#findComment-1238015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.