angelali Posted February 23, 2012 Share Posted February 23, 2012 Hello guys, I have created a mini image hosting website. Well, I have successfully coded the file upload, including security to allow certain image extensions and size as a beginner in PHP. However, only one thing remains is the image link. You can view the website on this address http://mini-image-hosting.99k.org/ where it is currently hosting on a free web hosting account with a free sub-domain. Right now, only the image can be uploaded and is being stored in a directory. Nevertheless, I want that when the person uploads an image, he gets also the link, for example: http://mini-image-hosting.99k.org/xxx.jpg something like that. Can you help me for this? Quote Link to comment Share on other sites More sharing options...
Glenskie Posted February 23, 2012 Share Posted February 23, 2012 any code? Quote Link to comment Share on other sites More sharing options...
angelali Posted February 23, 2012 Author Share Posted February 23, 2012 Here are the codes: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables $image = $_FILES['fileupload']['name']; $size = $_FILES['fileupload']['size']; $format = $_FILES['fileupload']['type']; $tmp_name = $_FILES['fileupload']['tmp_name']; //Check extensions and size $fileextension = strtolower(substr($image, strpos($image, '.') + 1)); $max = 204800; //Codes if (isset($image)) { if (empty($image)) { echo '<p class="error">Choose an image to upload!</p>'; } elseif ($fileextension !== 'jpg' && $fileextension !== 'jpeg' && $fileextension !== 'gif' && $fileextension !== 'png'){ echo '<p class="error">Only JPG, GIF and PNG are acceptable!</p>'; } elseif ($size > $max) { echo '<p class="error">Image must not exceed 200KB!</p>'; } elseif (file_exists("image/" .$image)) { echo '<p class="error">'.$image.' '.'already exists, choose another image or rename it to another name!'.'</p>'; } else { $location = 'image/'; move_uploaded_file($tmp_name, $location.$image); echo '<p class="success">Upload successful</p>'; echo '<p class="details">'.$image.'</p>'; } } } ?> Quote Link to comment 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.