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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.