Jump to content

[SOLVED] Generating link with basename


rilana

Recommended Posts

Hi guyes, I hope you can help me, I know this is suposed to be easy but I dont get it. After searching the web for a soulution I am hoping for your help now. I have a form which uploads files to the server, but now I wanna create an automatic link to the upload file. So if someone uploads a file it will generate and save the link to the file in the mysql database. I have the following:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "Die Datei " .  basename( $_FILES['uploadedfile']['name']). 
    " wurde erfolgreich hochgeladen.";
[color=red]$link = "http://rilana.biz/uploads/".basename( $_FILES['uploadedfile']['name']). ;[/color]
} else{
    echo "Beim hochladen der Datei gab es Probleme.";
}

 

This does not work, I dont know the syntax to combine the $link with the basename and also I am not clear if I need the stuff after basename.

I would aprechiate any imput on this. Thanks a lot, Rilana

Link to comment
Share on other sites

wow thanks that worked, I wasn't so far off after all :-) But the next problem is the following, I have a form where I say 

<input name="link" type="text" id="link" value="http://www." size="60" maxlength="500" /> 

this is sent to the php where I first upload files if there are any to upload. And thats where I create the $link new with

$link = "http://rilana.biz/uploads/".basename( $_FILES['uploadedfile']['name']) ;

if I echo the $link here its all perfect. But as I go down my script, I do this

//connecting
$dbname = ".";
$dbloc = ".";
$dbuser = ".";
$dbpass = ".";
mysql_connect($dbloc, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname) or die (mysql_error());
//end connecting

mysql_query("SET NAMES 'UTF8'");  

$link = strip_tags($_POST['link']);

if($link == "http://www.")
    {
   $link = "leer";
    }


$insert_str1  = "INSERT INTO news (link) VALUES ('$link')";

 

If I echo the $link here, it's leer. So I guess it still takes the value from the form, unstead of the value from the earlier lines of the script. How can I change that?  Is it evan possible to do this within one script?

 

Thanks for your help, Rilana

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.