Click here to Skip to main content
15,887,746 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: option 'explicit' for php Pin
fly90423-Sep-09 11:44
fly90423-Sep-09 11:44 
AnswerRe: option 'explicit' for php Pin
Marc Firth23-Sep-09 22:32
Marc Firth23-Sep-09 22:32 
GeneralRe: option 'explicit' for php Pin
Jeffrey Webster24-Sep-09 11:33
Jeffrey Webster24-Sep-09 11:33 
GeneralRe: option 'explicit' for php Pin
fly90424-Sep-09 13:51
fly90424-Sep-09 13:51 
GeneralRe: option 'explicit' for php Pin
Marc Firth24-Sep-09 22:55
Marc Firth24-Sep-09 22:55 
AnswerRe: option 'explicit' for php Pin
Vasudevan Deepak Kumar25-Sep-09 2:09
Vasudevan Deepak Kumar25-Sep-09 2:09 
QuestionDownload a file from a link? [modified] Pin
huh123422-Sep-09 19:38
huh123422-Sep-09 19:38 
AnswerRe: Download a file from a link? Pin
enhzflep22-Sep-09 23:05
enhzflep22-Sep-09 23:05 
I'll leave it to you to figure out GD for resizing the images, it's very simple. As will I leave it to you to come up with a naming scheme of the uploaded files.

The code's very simple and only needs Mat Kruse's Ajax Toolbox (AjaxRequest.js) to run. You could easily whip up the xmlhttprequest object and call yourself, though.


getFile.php

<?php
$url = $_GET["tgt"];
if ($url == "")
	die("No target specified");

// returns the part of a filename after the last slash.
function stripFilePath($filePath)
{
	return substr(strrchr($filePath, '/'), 1 );
}

// call with the url
// returns the read data
function loadHttpFile($url)
{  
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL, $url); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	$data = curl_exec($ch); 
	curl_close($ch); 
	return $data;
}

function saveHttpData($filename, $data)
{
	$fp = fopen($filename, "wb");
	fwrite($fp, $data);
	fclose($fp);
}

$newFilename = sprintf("uploads/%s", stripFilePath($url));
$displayedFilename = stripFilePath($newFilename);
$data = loadHttpFile($url);
saveHttpData($newFilename, $data);
printf ("<a href='%s'>%s</a>", $newFilename, $displayedFilename);
?>


downloadFile.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="../test/AjaxRequest.js"> </script>
<script type="text/javascript">

function myGetAjaxResponse(target, url)
{
  AjaxRequest.get(
    {
      'url':url,
      'onSuccess':function(req){ target.innerHTML=req.responseText; }
    }
  );
}		
function onGoBtn()
{
	var url, target, src;
	src = document.getElementById("urlInput").value;
	target = document.getElementById("tgtDiv");
	
	url = "getFile.php?tgt="+src;
	
	myGetAjaxResponse(target, url);
}
</script>
</head>
<body>
  <label>URL
  <input name="urlInput" type="text" id="urlInput" value="http://pplware.sapo.pt/wp-content/uploads/2007/10/20-xampp-logo-trio.jpg" size="80">
  </label>
  <br>
  <label>Download file & provide new link
  <input type="button" name="goBtn" id="goBtn" value="GO!" onclick="onGoBtn();">
  </label>
  <br>
  <div id="tgtDiv">Target Div(Link will go here)</div>
</body>
</html>

GeneralRe: Download a file from a link? Pin
huh123423-Sep-09 18:41
huh123423-Sep-09 18:41 
AnswerRe: Download a file from a link? Pin
fly90423-Sep-09 1:46
fly90423-Sep-09 1:46 
AnswerRe: Download a file from a link? Pin
Marc Firth23-Sep-09 1:54
Marc Firth23-Sep-09 1:54 
AnswerRe: Download a file from a link? Pin
huh123423-Sep-09 17:39
huh123423-Sep-09 17:39 
QuestionWeb pages do not display Pin
Steve Holdorf20-Sep-09 5:47
Steve Holdorf20-Sep-09 5:47 
AnswerRe: Web pages do not display Pin
Steve Holdorf20-Sep-09 7:40
Steve Holdorf20-Sep-09 7:40 
GeneralRe: Web pages do not display Pin
Marc Firth28-Sep-09 5:58
Marc Firth28-Sep-09 5:58 
QuestionAnti Frame Breaker Code Pin
stambekar18-Sep-09 1:31
stambekar18-Sep-09 1:31 
AnswerRe: Anti Frame Breaker Code Pin
enhzflep18-Sep-09 5:35
enhzflep18-Sep-09 5:35 
GeneralRe: Anti Frame Breaker Code Pin
stambekar20-Sep-09 19:15
stambekar20-Sep-09 19:15 
GeneralRe: Anti Frame Breaker Code [modified] Pin
enhzflep22-Sep-09 18:24
enhzflep22-Sep-09 18:24 
QuestionPython Debugger? [modified] Pin
Joe Woodbury16-Sep-09 11:22
professionalJoe Woodbury16-Sep-09 11:22 
AnswerRe: Python Debugger? Pin
Med7at24-Sep-09 18:51
Med7at24-Sep-09 18:51 
GeneralRe: Python Debugger? Pin
anand mohan12329-Sep-09 14:30
anand mohan12329-Sep-09 14:30 
Questionupload photo Pin
pallavi shrivastava16-Sep-09 3:28
pallavi shrivastava16-Sep-09 3:28 
AnswerRe: upload photo Pin
EliottA16-Sep-09 6:10
EliottA16-Sep-09 6:10 
AnswerRe: upload photo Pin
Marc Firth17-Sep-09 14:37
Marc Firth17-Sep-09 14:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.