Hi

I am developing an image hosting website.I want images uploaded to go to another server , not the one where the script is hosted.For e.g i want images to be uploaded to http://i1.mysite.com instead of http://mysite.com/uploads
Suppose i have this code to upload file to server

<form action="http://mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
    <input type="file" name="image" id="file_upload" />
    <input type="submit" value="Upload" id="upload_submit" />
</form>

Ofc i could always change the form action to
<form action="http://i1.mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">

But I'd be redirected to http:/i1.mysite.com/upload after upload
I am thinking that i could create a php that do ftp connection to the storage server(aka where the images will be stored).However how will i make the storage server be recognise as .i1 (sorry if noob question but more a learning project for me that i intend to use later)

Also i want the site to redirect to this after upload
http://mysite.com/upload
then on the upload page i will show link to image.For e.g
http://i1.mysite.com/upload/i3fRT.png

I am doing this because of the following reason:
1)Need to have the ability to add new servers as site grows(aka adding new server i2 , i3 etc)
2)Want optimum for performance for user - can tweak the servers which will store images to server them best at most efficient way

Do you think it is logical to use a dedicated server to store both the site script and images , then when space becomes low on dedicated server to add some vps e.g i2, i3?

Need your views , suggestion and help
Much appreciated:)

Recommended Answers

All 15 Replies

I am not sure about performance.
1) you have to upload file using script to same server where script is available.
2) copy that file to another server using ftp funciton of php
3) delete file from script server

commented: From Khav +2

Thanks you for your response
But how resource intensive is this process.Can anyone tell me the most efficient way to do this.

I usually keep things on same server as I never had big number of files. Huge sites may be keeping file separate server.
I dont think bad performance if you keep files on same server, in case of medium sites

There is a possiblity that site grows so i need this feature to be ready just in case
However i don't know how to make this feature.
Here is what i have difficulty in doing
suppose i have a separate server like 67.57.183.23 (just a random number) and i want to add upload images to it

I need link to the separate server like
http://i1.mysite.com/upload/i3fRT.png
Thus when user open this link in browser , image in 67.57.183.23/upload/i3fRT.png open.
How can this be done?

Yes
I guess you will save i3frt.png name in database somewhere,
then when user uploads it copy that file to ftp server at location server/upload

if you show link in your file like server/upload/image.png
then it will also work fine

you are right , http://67.57.183.23/upload/i3rft.png would work
but it don't look good also exposes server too much.
Uploaders should not know Ip of secondary server
i need i1 to represent the secondary server

showimage.php

<?php
    $form_no = $_GET['imgid'];


    if($_GET['type']==1)
        $file="p{$form_no}_photo.jpg";
    elseif($_GET['type']==2)
        $file="p{$form_no}_sign.jpg";
    $instr = fopen("http://92.43.223.43/upload/{$file}","rb");//here you can give url of your ftp server
    $bytes = fread($instr,filesize("http://92.43.223.43/upload/{$file}"));
    header("Content-type: image/jpeg");
    print $bytes;
    exit ();

?>

html

<img src ='showimage.php?imgid=i3rft'>

What i have given you will show http://i1.mysite.com/showimage.php?imgid=i3rft to user. But user will never able to know actual server address where image is stored.

Showimage.php will silently show image from remote server without revealing remote server address

If you want to show like http://i1.mysite.com/upload/image.png and want to get image from remote then I am not sure how to do that

commented: Thanks for the interest +0

If you want to show like http://i1.mysite.com/upload/image.png and want to get image from remote then I am not sure how to do that

Thats precisely what i want to achieve:D
Ty for the interest dude

anyone else to attempt to help me......

That's so much bro
Thread closed and one vote for you:P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.