Good morning,
All of a sudden my upload refuses to move the data. It will move the file name but nothing in the file. If someone could take a look I would greatly appreciate it.
<?php
//get file uploaded from handheld;
$webServer="../PHP/";
if($img1_name!=""){
@copy("$img1","$webServer/$img1_name") or die("Couldn't copy the file");
}
else{
die("No input file specified!$img1_name");
}
$uploaddir = '../PHP/';
$filename = $uploaddir . $_FILES['img1']['name']; // File to open.
function viewlog($filename) {
$fp = fopen($filename, "r");
$file = fread($fp,65535);
$string = eregi_replace(", ", ",", $file);
$replaced = eregi_replace("\r", "\r\n", trim($string));
fclose($fp);
return $replaced;
}
//insert into new file
$inputString = viewlog($filename);
$uploadfile = "Upload";
$setpath = $uploaddir.$uploadfile;
$setfile = $setpath.uniqid(rand(),1).'.txt'; ;
$fp = fopen($setfile, "w+" );
$fw = fwrite( $fp, $inputString );
fclose( $fp);
//truncate the file used
$del = fopen($filename, "w+");
fclose($del);
if(!$fw) echo "Couldn't write the entry--no data to transfer. <a href=\"index.php\">Would you like to try again?</a>";
else //echo "Successfully wrote to the file. <a href=\"ErrorCheck.php\">Go on to check your errors</a>";
//get a mssql connection
$link = mssql_connect('HQMSDB05');
if (!$link) {
die('Cannot connect to database server');
}
// set the current db
$db_selected = mssql_select_db('Yardcheck', $link);
if (!$db_selected) {
die ('Cant use db ');
}
//new file name
$fcontents = file ($setfile);
foreach($fcontents as $value)
{
$line = str_replace("\r", " ", trim($value));
$arr = explode(",", $line);
$sql = "Insert Into tblM5Upload (Location,TrailerID,TrailerType,
Classification,Contents,Comments,UpLoadDate,UpLoadTime,Source)
values ('".
implode("','", $arr) ."')";
@mssql_query($sql);
$setUpLoadTime = "Update tblM5Upload
set WhenUpLoaded = convert(varchar(30), DATEADD(hh, DATEDIFF(hh, 0, GetDate()), 0))
where WhenUpLoaded is NULL";
mssql_query($setUpLoadTime);
}
//tell them how many trailers they uploaded
$result = mssql_query ("select count(trailerid)as Total from tblm5upload");
while($r=mssql_fetch_array($result))
{
$s_result=$r["Total"];
}
echo "<br>";
echo "<b> You have uploaded " . $s_result . " trailers. If this is not correct <a href=\"testUpload.php\">please delete the current upload and try again.</a><b>";
echo "<br>";
echo "If this is correct <a href=\"ErrorCheck.php\">Go on to check your errors</a>";
//clean up our mess delete the upload intermediary file
$doc = $setfile;
$path = '../PHP/';
$unlink = unlink($path . $doc);
//delete the upload text file
$doc = $filename;
$path = '../PHP/';
$unlink = unlink($path . $doc);
?>