Hi, i have problem with the finalised file content not being complete i.e. it is cut off just before the eof is reached.
if ($html){
if ($html_type != "text/html")
{
$error .= "Problem: This file is of type ".$html_type." i.e. file is not mime \'text/html\'";;
form($error);
exit;
}
if ($html_size == 0)
{
$error.= "Problem: uploaded html file is zero length";
$i++;
continue;
}
if (!is_uploaded_file($html))
{// possible file upload attack detected
$error .= "<span class=\"black13lh18j\">Possible breach detected with '$html', not uploading.</span>";
form($error);
exit;
}
// Clean up file name (only lowercase letters, numbers and underscores)
$html_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($html_name))));
$dest_html_file = $the_path."/".$temp_dir."/".$html_name;
move_uploaded_file($html, $dest_html_file);
//if there are no uploaded images
if( in_array(" ", $userfile)){
echo "There are no uploaded images for html file ".$html_name;
$fp = fopen($dest_html_file, "rb");
$story_text = addslashes(fread($fp, filesize($dest_html_file)));
fclose($fp);
}
}
....
$temp_destination = $the_path."/".$temp_dir."/".$userfile_name[$i];
switch($overwrite_mode) {
case 1: // overwrite mode
move_uploaded_file($userfile[$i], $temp_destination);
break;
case 2: // create new with incremental extention
$ext = ".".getext($userfile_name[$i]);
//echo $ext."\n";
echo "destination path is ".dirname($temp_destination)."<br>";
echo "file name is ".basename($temp_destination, $ext). $copy . $ext."<br>";
while(file_exists(dirname($temp_destination)."/".basename($temp_destination, $ext). $copy. $ext)) {//. $copy . $ext
$copy = "_copy" . $n;
$n++;
}
$temp_destination = dirname($temp_destination)."/".basename($temp_destination, $ext). $copy . $ext;
$path_pic[$i] = $temp_destination;//placeholder for form var & re-transmission
move_uploaded_file($userfile[$i], $temp_destination);
unset($copy);
unset($n);
break;
case 3: // do nothing if exists, highest protection
if(file_exists($temp_destination)){
$status.= "File "" . $temp_destination . "" already exists \n and has not been overwritten as requested";
} else {
move_uploaded_file($userfile[$i], $temp_destination);
}
break;
default:
$error.= "\n<b>Due to an error The following file".$userfile_name[$i]." could not be uploaded \n</b>";
}
...
if($_REQUEST['post']){
$pic_name[$i] = basename($temp_destination);
$destination = $the_path."/".$page."/".$story."/".$pic_name[$i];
copy($temp_destination, $destination);
//nb. if copy need new image_copy name i.e. basename($destination_of_copied_image)
$url_destination = "http://".$_SERVER['HTTP_HOST']."/pec/".$page."/".$story."/".$pic_name[$i];
if($html){
$fp = fopen($dest_html_file, "rb");
$html_contents = stripslashes(fread ($fp, filesize ($dest_html_file)));
fclose ($fp);
echo "<p>The destination for this image path's on post (direct) is ".$url_destination."<br>";
//need to keep place holder for original unvalidated name and scan file for this
$html_contents = addslashes(preg_replace("/<img src=\"(http(s?):\/\/){0}(www\.)?([\w\.\/\&\=\?\-]+)($orig_pic_name[$i])\"/i", "<img src=\"$url_destination\" alt=\"$pic_name[$i]\"",$html_contents)); //search was ..($userfile_name[$i]) alt=\"$5\" "
$fp = fopen($dest_html_file, "wb");
fwrite($fp, $html_contents);
fclose($fp);
$qry = "update story set story_text = '$html_contents'
where id = ".$story;
//echo $query."<br>";
$result = mysql_query($qry);
if(!$result)
{
$error .= "<p>can't insert html into table, please try again later</p>\n";
}
}
$query = "update story set picture$i = '$url_destination'
where id = ".$story;
//echo $query."<br>";
$result = mysql_query($query);
if(!$result)
{
$error .= "<p>can't insert file path into table, please try again later</p>\n";
}
}
$i++;
} # end while
Sorry 'bout the long winded-ness - basically this script manages multiple file uploads , if it detect's if an html file and some supporting images are uploaded, it will overwrite the original image path's with the final destination of where these images will be located on the server, into the html file which is then read into a database table - this basically just gives the content manager the flexibility on whether to store the images locally or leave the image url's as is if they have http reference.
There are overwrite modes where the images can be overwritten or copied or not overwriiten if they already exist.
For some reason the full html file content is correctly inserted into the mysql db table using the 'copy' or 'off' (images not overwritten if already exist on server) modes but not if the overwrite mode is 'yes' i.e. overwrite the same image if it exists.
Is this a file pointer. file cache or mysql db issue?
Regards
Synfield