Jump to content

Output URL shortened (Using Bit.ly) [Whats wrong with my code]


andre1990

Recommended Posts

I have an upload site whereby people get direct file links. I want to output links as bit.ly

 

My code stands as following:

 

<?php
$content = file_get_contents("http://api.bit.ly/v3/shorten?login=andre1990
&apiKey=R_56a95c84d089129012516e24806c3649
&longUrl='.urlencode($final).'&format=txt");
?>

//Input type because i want a text box with the link in it.

<input type="text" size="28" onClick=select() value="<?php echo $content; ?>" READONLY><p />

 

where $final is the uploaded file URL.

 

But it just outputs nothing, no bit.ly link.

 

Any help?

 

Link to comment
Share on other sites

You are using the wrong quotes when entering the urlencode part of the string.

Change

file_get_contents("http://api.bit.ly/v3/shorten?login=andre1990
&apiKey=R_56a95c84d089129012516e24806c3649
&longUrl='.urlencode($final).'&format=txt")

to

file_get_contents("http://api.bit.ly/v3/shorten?login=andre1990
&apiKey=R_56a95c84d089129012516e24806c3649
&longUrl=".urlencode($final)."&format=txt")

Link to comment
Share on other sites

Hi, thanks for the help, still blank though.

 

I currently have:

 

$final = $server."/".$destination."/".$name;

$contents = file_get_contents("http://api.bit.ly/v3/shorten?login=andre1990
&apiKey=R_56a95c84d089129012516e24806c3649
&longUrl=".urlencode($final)."&format=txt")

?>

 

Echoed out:

 

<input type="text" size="28" onClick=select() value="<?php echo $contents;?>" READONLY><p />

 

Struggling to see the issue.

Link to comment
Share on other sites

You are missing a ; at the end of file_get_contents()

Is the URL in file_get_contents all on one line?

$content = file_get_contents("http://api.bit.ly/v3/shorten?login=andre1990&apiKey=R_56a95c84d089129012516e24806c3649&longUrl=".urlencode($final)."&format=txt");

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.