Jump to content

Image Hosting Website Link


angelali

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/257632-image-hosting-website-link/
Share on other sites

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>';
}
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.