JJohnsenDK Posted December 4, 2006 Share Posted December 4, 2006 Heyas 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 https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/ Share on other sites More sharing options...
onlyican Posted December 4, 2006 Share Posted December 4, 2006 $destination = "../../../That could be whyTry setting up a directory starting from root$destination = $_SERVER['DOCUMENT_ROOT']."/billeder/news/".$FILES['filnavn']['name']; Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-134982 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 thats not working eihter :-\ simply cant see the error. Its very wierd :-Xanyone ohter suggentions? Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-134990 Share on other sites More sharing options...
onlyican Posted December 4, 2006 Share Posted December 4, 2006 at the top of the script add this lineerror_reporting(2047);this will show all errors Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-134998 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 okay didnt know that one... but it doesnt show any errors... Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-134999 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 sry to quick.. it works.. gonna check the errors... thanks Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135000 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 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 67Notice: Undefined index: pl_pic in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 68I 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 https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135010 Share on other sites More sharing options...
onlyican Posted December 4, 2006 Share Posted December 4, 2006 ignore the underfined index,Simply means you have a variable in a condition that is not namedFor Exampleif($_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 usingChange this linemove_uploaded_file($tempfile, $destination);toif(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 https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135012 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 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 67Notice: Undefined index: pl_pic in C:\Programmer\xampp\htdocs\sifnet\administration\wof_pl_commit.php on line 68There has been an erorr uploading the file.It must be something with that Undefined index, right? Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135028 Share on other sites More sharing options...
onlyican Posted December 4, 2006 Share Posted December 4, 2006 show me line 65 - 70 Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135044 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 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 https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135050 Share on other sites More sharing options...
onlyican Posted December 4, 2006 Share Posted December 4, 2006 its saying that the $_FILES["pl_pic"] does not existcheck that on the form, the field name is pl_pic<input type='file' name='pl_pic' /> Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135061 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 it is:<input name="pl_pic" type="file" id="file" value="<?php echo $pl_pic; ?>"/>Thats why i dont understand the error. Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135065 Share on other sites More sharing options...
JJohnsenDK Posted December 5, 2006 Author Share Posted December 5, 2006 isnt there anyone who can help me with this? Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135346 Share on other sites More sharing options...
genericnumber1 Posted December 5, 2006 Share Posted December 5, 2006 for your form.. do you have <form action="whatever" method="post" enctype="multipart/form-data">people often forget the enctype for file uploads.... people being me Link to comment https://forums.phpfreaks.com/topic/29413-why-does-this-code-not-upload-picturefile-to-folder/#findComment-135349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.