Reply to Re: problems using copy() and rename()

Your name:

Reply:


Posted by mantrid on 10/21/06 14:16

"mantrid" <ian.dandav@virgin.net> wrote in message
news:eUp_g.42060$6C2.34098@newsfe6-gui.ntli.net...
>
> "peter" <submit@flexiwebhost.com> wrote in message
> news:ehd81o$cu8$1@aioe.org...
> >
> > "mantrid" <ian.dandav@virgin.net> wrote in message
> > news:%7o_g.143$76.75@newsfe5-win.ntli.net...
> > > Im trying to move a file but am having luck
> > > my code is below. The temp and target paths are valid as they echo
> > > correctly. but I cant get the copy() function to work, or the rename()
> > > function
> > >
> > > $target_path = $targetdir . basename($uploadedfile["name"][$x]);
> > > $temp_path = $tempdir. basename($uploadedfile["name"][$x]);
> > >
> > > echo "Target - ".$target_path." Temp - ".$temp_path."<br>";
> > >
> > > copy($temp_path, $target_path);
> > >
> > > has any one experienced this problem?
> > >
> >
>
>
>
> > are you receiving any error if so what is it? Also if it is as it looks
> and
> > is a file that has been uploaded then why not use the
move_uploaded_file()
> > function.
> >
> >
>
> I tried with the move_uploaded_file() originally but this didnt work
> either. I thought maybe it only works initially with $_FILES as I
understand
> it checks that a file has been uploaded and returns negative if it cant
find
> one.
> Ther is no error message it appears to work as my success message is
> displayed but the file is not there
>
>

Here is the full code. as you can see ive commented out much of it to try
and narrow down the problem. Ive used an echo to check that the session
variables are valid. but the file just will not move

$userid=$_SESSION[userid];
$delquest=$_SESSION[delquest];
$archivequest=$_SESSION[archivequest];
$changedquests=$_SESSION[changed];
$questids=$_SESSION[questids];
$imagechanged=$_SESSION[imagechanged];
$delimage=$_SESSION['delimage'];
$msg=$_SESSION['msg'];
$uploadedfile=$_SESSION['uploadedfile'];
$imagepath=$_SESSION['imagepath'];
$questuserid=$_SESSION[questuserid];
$imagequestindex=$_SESSION[imagequestindex];

if(count($imagechanged)>0){
$targetdir = "pupiltester/";
$tempdir= "temp/";
$allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
for ($x = 0; $x < count($imagequestindex); $x++){
if(!empty($uploadedfile["name"][$x])){

$target_path = $targetdir . basename($uploadedfile["name"][$x]);
$temp_path = $tempdir. basename($uploadedfile["name"][$x]);
$imagefile=$imagepath[$x];
echo "Userid - ".$questuserid[$x]." Target - ".$target_path." Temp -
".$temp_path." To replace - ".$imagefile."<br>";
copy("$temp_path", "$target_path");
//if($uploadedfile["size"][$x] < 35841) {
//if(preg_match("/\." . $allowed_file_types . "$/i",
$uploadedfile["name"][$x])) {
if(file_exists($target_path)){
//if($questuserid[$x]=$userid){
$sql2 = "UPDATE questions SET
ImagePath='".$uploadedfile["name"][$x]."' WHERE ImagePath='".$imagefile."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding image name ".$uploadedfile['name'][$x]."
to database: " . mysql_error()."</span>";

if(file_exists($targetdir.$imagefile)){unlink($targetdir.$imagefile);}
//$msg.="<br><span class='greenbody'>Link formed to your existing
file by the name of ".$uploadedfile["name"][$x].".</span>";
//}else{
//$msg.="<br><span class='RedWarning'>A image by the name of
".$uploadedfile["name"][$x]." already exists for another users question.
Please rename it and try again.</span>";
//}
}else{
rename($temp_path, $target_path);
//if(move_uploaded_file($temp_path, $target_path)){
//$msg.="<br><span class='greenbody'>Uploaded the image
".$uploadedfile["name"][$x]." (" .$uploadedfile["type"][$x]. ",
".ceil($uploadedfile["size"][$x] / 1024) . " Kb).</span>";
//if($uploadedfile['name'][$x]!==''){
$sql2 = "UPDATE questions SET
ImagePath='".$uploadedfile["name"][$x]."' WHERE ImagePath='".$imagefile."'";
$addquest = mysql_query($sql2) or $msg.="<br><span
class='RedWarning'>Problem adding image name ".$uploadedfile['name'][$x]."
to database: " . mysql_error()."</span>";

if(file_exists($targetdir.$imagefile)){unlink($targetdir.$imagefile);}
//}
//}else{
//$msg.="<br><span class='Red Warning'>Error uploading image -
".$uploadedfile['name'][$x].$uploadedfile['error'][$x]."</span>";
//}
}
//}else{
//$msg.="<br><span
class='RedWarning'>".$uploadedfile['name'][$x].$uploadedfile['error'][$x]."
not uploaded. Not a valid image file.</span>";
//}
//}else{
//$msg.="<br><span class='RedWarning'>".$uploadedfile['name'][$x]." is
greater than 35Kb.</span>";
//}
}
}
//$_SESSION['msg']=$msg;
//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

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