Image uploader by URL

Discussion in 'PHP' started by Agent_Dweeb, Jun 5, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Hello DP users! Nice to see you all.

    I need a script like imageshack where you can enter your url for the picture to upload and the standard browsing option and then uploads to the server in a directory but no image resizing and thumbnails, but if there is a free script out there then great!

    Exactly like one, please don't flame me if this question has been asked before but I really need something like this.
     
    Agent_Dweeb, Jun 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Jun 5, 2007 IP
  3. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Does it do everything what I need?
     
    Agent_Dweeb, Jun 5, 2007 IP
  4. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't know to use that.
     
    Agent_Dweeb, Jun 7, 2007 IP
  5. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks sitefever for the script.
     
    Agent_Dweeb, Jun 8, 2007 IP
  6. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hello DP users! Nice to see you all.

    I need a script like imageshack where you can enter your url for the picture to upload and the standard browsing option and then uploads to the server in a directory but no image resizing and thumbnails, but if there is a free script out there then great!
     
    Agent_Dweeb, Jun 24, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    nico_swd, Jun 24, 2007 IP
  8. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Please can you help me buy making the files into a zip format

    Because I don't understand it =/
     
    Agent_Dweeb, Jun 24, 2007 IP
  9. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Please any one, help!
     
    Agent_Dweeb, Jul 1, 2007 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    Have a look at www.phpclasses.org - There are some scripts that can manage ZIP files.
     
    nico_swd, Jul 1, 2007 IP
  11. Agent_Dweeb

    Agent_Dweeb Peon

    Messages:
    5,607
    Likes Received:
    384
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Heres my current code

    <?
    
    	include("include/common.php");
    	include("include/header.php");
    
    function getmicrotime(){
    list($usec,$sec)=explode(" ",microtime());
    return ((float)$usec+(float)$sec);
    }
    $time_start=getmicrotime();
    
    	if($loggedin){
    		include("include/accmenu.php");
    	}
    	if( $_POST['submit'] && $_FILES['attached']['name'] ){
    		$ok_filetypes = explode("|",$att_filetypes);
    		if (!$_FILES['attached']['error'] && $_FILES['attached']['size'] > $att_max_size*1024){
    			errform('<CENTER>Sorry, but the attached file is too large. Please reduce the size of it\'s contents.</CENTER><BR><BR>'); // #err
    			$step = 1;
    		}
    		$filename = (!$_FILES['attached']['error'] ? substr( basename($_FILES['attached']['name']), -30 ) : '');
    		$x = strtolower( substr($_FILES['attached']['name'], -3));
    		if($filename && !in_array($x, $ok_filetypes) ){
    			errform('<CENTER>Sorry, the filetype you have tried to upload is not allowed.</CENTER><BR><BR>');
    			$step = 1;
    		}
    		if(!$posterr){
    			if(!isset($_GET["ipaddress"]) || ($_GET["ipaddress"] == "")) {
    				$ipaddress = $_SERVER['REMOTE_ADDR'];
    				$local = 1;
    			} else {
    				$ipaddress = $_GET["ipaddress"];
    				$local = 0;
    			}
    			$uniq = substr( md5(uniqid (rand())), 0, 10 );
    			$ext = strtolower( substr($_FILES['attached']['name'], -3));
    			move_uploaded_file($_FILES['attached']['tmp_name'], $att_path."/".$uniq.".".$ext );
    			$strQuery  = "INSERT INTO images SET ";
    			$strQuery .= "filename='".$uniq.".".$ext."',";
    			$strQuery .= "ipaddress='{$ipaddress}',";
    			$strQuery .= "date='".time()."',";
    			$strQuery .= "pkey='{$uniq}',";
    			if($myuid){
    				$strQuery .= "user='{$myuid}',";
    			}
    			$strQuery .= "status='1'";
    			$result = mysql_query($strQuery) or die( mysql_error() );
    			$aid = mysql_insert_id();
    			if($aid){
    				$filen = $siteurl."/".str_replace('./', '', $att_path)."/".$uniq.".".$ext;
    				$filen = str_replace('http://','%%',$filen);
    				$filen = str_replace('//','/',$filen);
    				$filen = str_replace('%%','http://',$filen);
    				$step = 2;
    			}else{
    				$step = 1;
    			}
    		}
    	}else{
    		$step = 1;
    	}
    	if($step == 1){
    ?>
    		<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
    		<tr>
    			<td>
    				<div align=center>
    				<form ENCTYPE="multipart/form-data" method="post" name="form1">
    					<INPUT NAME="attached" TYPE="file"  size="50"><br>
    					File extensions allowed: <b><?=implode("</b>, <b>",explode("|",$att_filetypes))?></b><br>
    					File size limit: <b><?=$att_max_size?>KB</b>
    					<br><br>
    					<input type="submit" name="submit" value="Upload Image">
    				</form>
    				</div>
    			</td>
    		</tr>
    		</table>
    <?
    	}else{	?>
    <div align="center"><b>Your image has been successfully uploaded!</b><br>
      <br>
    </div>
    <table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
    		<tr>
    			<td><div align="center"><img src="<?=$filen?>"></div></td>
    		</tr>
    		<tr>
    			<td><div align="center"><br>
    				To insert this image in a message board post copy and paste the following
    				code:<br>
    				<textarea name="textarea" cols="100" wrap="soft" rows="3">[url=<?=$siteurl?>][img]<?=$filen?>[/img][/url]</textarea>
    			</div></td>
    		</tr>
    		<tr>
    			<td><div align="center"><br>
    				To send this image to friends and family, copy and paste this code: <br>
            <textarea name="textarea2" cols="100" rows="4"><?=$filen?></textarea>
          </div></td>
    		</tr>
    		<tr>
    			<td><div align="center"><br>
    				To insert this image using HTML, copy and paste the following
    				code:<br>
    				<textarea name="textarea3" cols="100" wrap="soft" rows="3"><a href="<?=$siteurl?>" target="_blank"><img alt="Image Hosted by <?=$sitename?>" src="<?=$filen?>" /></a></textarea>
    			</div></td>
    		</tr>
    		<tr>
    			<td>&nbsp;</td>
    		</tr>
    		</table>
    
    <?
    	include("include/footer.php");
    ?>
    PHP:
    All this does is you browse through your files and select a file, then uploads the file to the server in the /uploads/ folder

    I want a script where you enter your url and does the same thing

    Just something very simple!
     
    Agent_Dweeb, Jul 1, 2007 IP
  12. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Well, suppose you get the URL from user, generate the filename using

    $uniq = substr( md5(uniqid (rand())), 0, 10 );

    and also find someway to get the correct extension and put it in $ext.
    You can do
    
    $imgdata = file_get_contents($url);
    $fp = fopen($uniq.'.'.$ext,'wb');
    fwrite($fp,$imgdata);
    fclose($fp);
    
    PHP:
    After that there will be the code for adding it to the database, as it is given in your code.

    $strQuery = "INSERT INTO images SET ";
    .. and so on.

    I have just given a general idea of how to do it. You will have to adapt it for your use.

    ~
    coderlinks
     
    coderlinks, Jul 1, 2007 IP
Thread Status:
Not open for further replies.