Jump to content

Why does this code not upload picture/file to folder?


JJohnsenDK

Recommended Posts

Hey

as the subject says, why doesnt this code upload the file to the folder, i just cant find the error:

[code]
        $_POST['news_headline'] = strip_tags($_POST['news_headline']);
$_POST['news_text'] = strip_tags($_POST['news_text']);
$_POST['news_billede'] = strip_tags($_POST['news_billede']);

if (empty($_POST['news_headline'])){
echo "<br /><br /><font color='#FF0000'>Du har ikke skrevet en Nyheds overskrift.</font>";
}
if (empty($_POST['news_text'])){
echo "<br /><br /><font color='#FF0000'>Du har ikke skrevet en Nyheds tekst.</font>";
}
else{
if (isset($_POST['submit'])){
if (!empty($_POST['news_headline'])){
echo "Nyheden ".$_POST['news_headline']." er blevet tilføjet.";
}
if (isset($_FILES['news_billede'])) {
print "<br /><br />Fil, der er blevet overført: {$_FILES['news_billede']['name']}<p>\n";
$hent = mysql_query("SELECT * FROM katrinelund_news");
$overskrift = $_POST['news_headline'];
$tekst = $_POST['news_text'];

$vis = mysql_query("INSERT INTO katrinelund_news SET news_headline = '".$overskrift."', news_text = '".$tekst."', news_billede ='".$_FILES['news_billede']['name']."'");
}

{
$tempfile = $_FILES['filnavn']['tmp_name'];
$destination = "../../../billeder/news/{$_FILES['filnavn']['name']}";
move_uploaded_file($tempfile, $destination);
}
}
}[/code]
Link to comment
Share on other sites

Okay i got it to work in a script with $_SERVER[PHP_SELF] but when i use action to a commit page where i use switch it doesnt work. These errors comes:

Notice: Undefined index: pl_pic in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 67

Notice: Undefined index: pl_pic in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 68

I dont understand it, because i also use pl_pic to define where in the database the name of the file should be stored. If i try to use $_POST like this:
$tempfile = $_FILES [$_POST['pl_pic']]['tmp_name'];

i get this error:
Notice: Undefined index: 2005-Suzuki-Grand-Vitara-05811041990001.JPG in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 67.

Why cant the script find pl_pic?

Here is the code:

[code]switch( $_GET['type'] ){
            case "movie":
              $sql = "INSERT INTO
                        wof_pl
                        ( wof_pl_name,
                        wof_pl_pos,
                        wof_pl_side,
                        wof_pl_shirt,
                        wof_pl_birth,
                        wof_pl_pic,
                        wof_pl_debut,
                        wof_pl_height,
                        wof_pl_weight,
                        wof_pl_clubs,
wof_pl_year,
                        wof_pl_text )
                    VALUES
                        ( '".$_POST['pl_name']."' ,
                        '".$_POST['pl_pos']."' ,
                        '".$_POST['pl_side']."' ,
                        '".$_POST['pl_shirt']."',
                        '".$_POST['pl_birth']."',
                        '".$_POST['pl_pic']."',
                        '".$_POST['pl_debut']."',
                        '".$_POST['pl_height']."',
                        '".$_POST['pl_weight']."',
                        '".$_POST['pl_clubs']."',
'".$_POST['pl_year']."',
                        '".$_POST['pl_text']."' )
                    ";  
{
$tempfile = $_FILES ['pl_pic']['tmp_name'];
$destination = "images/{$_FILES['pl_pic']['name']}";
move_uploaded_file($tempfile, $destination);
}
              break;
 
        }
        break;[/code]
Link to comment
Share on other sites

ignore the underfined index,
Simply means you have a variable in a condition that is not named

For Example

if($_POST["myname"]){

if there is no POST values then that is a underfined index.

This may stop the script if one of them vars is something your script is using

Change this line

move_uploaded_file($tempfile, $destination);
to

if(move_uploaded_file($tempfile, $destination)){
echo "File has been uploaded<br />\n";
}else{
echo "There has been an erorr uploading the file.<br />\n";
}

Link to comment
Share on other sites

yeah but that missing variable is the one which should create the image... When i input the code you posted i get the same msg plus the error msg you wrote:


Notice: Undefined index: pl_pic in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 67

Notice: Undefined index: pl_pic in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 68
There has been an erorr uploading the file.

It must be something with that Undefined index, right?
Link to comment
Share on other sites

This is line 65 to 76.

[code]                    ";  
{
$tempfile = $_FILES['pl_pic']['tmp_name'];
$destination = "images/{$_FILES['pl_pic']['name']}";
if(move_uploaded_file($tempfile, $destination)){
echo "File has been uploaded
\n";
}else{
echo "There has been an erorr uploading the file.
\n";
}
}[/code]
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.