Reply to can you set FILES[] variables to session variables?

Your name:

Reply:


Posted by mantrid on 10/17/06 19:04

I have some code to upload files to my site. it works when the <input
type="file" > is posted once even when I use session variables from the
posted variables but when I carry those session variables to a new page the
upload will not work. despite the variables being set. I have echoed then on
the second page and they display correctly but they just dont work in the
move_uploaded_file() function. I get the error message

Error uploading image - myfile.jpg0

The 'Error uploading image - myfile.jpg' is my message but where there is
the () I am expecting the php error message to be returned from
$_SESSION['uploadedfile']['error'][$x]

Is this behaviour normal ie you cant set a session variable from posted
FILES[] varaibles, or does the problem lie with my script. Ive included it
below idf it helps

if($imagechanged){
for ($x = 0; $x < count($imagechanged); $x++){
if($_SESSION['uploadedfile']["name"][$x]!==''){
$targetdir = "/questiondbase/pupiltester/";
$allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
$target_path = $targetdir .
basename($_SESSION['uploadedfile']["name"][$x]);
echo $imagechanged[$x]." -
".$_SESSION['uploadedfile']["tmp_name"][$x]." - ".$target_path;
//echo $targetdir . $_SESSION['imagepath'][$x]."<br>";
if($_SESSION['uploadedfile']["size"][$x] < 35841) {
if(preg_match("/\." . $allowed_file_types . "$/i",
$_SESSION['uploadedfile']["name"][$x])) {
unlink($targetdir . $_SESSION['imagepath'][$x]);
if(file_exists($target_path)){
$msg.="<br><span class='RedWarning'>A file by the name of
".$_FILES["uploadedfile"]["name"][$x]." already exists. Please rename it and
try again.</span>";
} else {
if(move_uploaded_file($_SESSION['uploadedfile']["tmp_name"][$x],
$target_path)){
$msg.="<br><span class='greenbody'>Uploaded
".$_SESSION['uploadedfile']["name"][$x]." ("
..$_SESSION['uploadedfile']["type"][$x]. ",
".ceil($_SESSION['uploadedfile']["size"][$x] / 1024) . " Kb).</span>";
//if($uploadedfile['name'][$x]!==''){
$sql2 = "UPDATE questions SET
ImagePath='".$_SESSION['uploadedfile']["name"][$x]."' WHERE
ImagePath='".$_SESSION['imagepath'][$x]."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding file name
".$_SESSION['uploadedfile']['name'][$x]." to database: " .
mysql_error()."</span>";
//}
}else{
$msg.="<br><span class='Red Warning'>Error uploading image -
".$_SESSION['uploadedfile']['name'][$x].$_SESSION['uploadedfile']['error'][$
x]."</span>";
}
}

}else{
$msg.="<br><span
class='RedWarning'>".$_SESSION['uploadedfile']['name'][$x].$_SESSION['upload
edfile']['error'][$x]." not uploaded. Not a valid image file.</span>";
}
}else{
$msg.="<br><span
class='RedWarning'>".$_SESSION['uploadedfile']['name'][$x]." is greater than
35Kb.</span>";
}
}
}
echo("<br><br><div align='center'>".$msg."<br><br><a
href='usersquestions.php' class='BodyLink'>Return</a></div>");
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация