alanl1
-
Posts
80 -
Joined
-
Last visited
Posts posted by alanl1
-
-
Hi DavidAM
I have managed to pull the variable values out but its very messy I only want the headings once and it seems to be repeating them for every row
here is my code to date, I have added headings[1] through to [26] manually as i know the spreadsheet has 26 columns, but what it it has only 5 or 27 or something like that
if (($handle = fopen($filename, "r")) !== FALSE) {
$headings = array(); # MAD - Added
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if (empty($headings)) $headings = $data; # MAD - Added
echo $headings[0];
echo $headings[1];
echo $headings[2];
echo $headings[3];
echo $headings[4];
echo $headings[5];
echo $headings[6];
echo $headings[7];
echo $headings[8];
echo $headings[9];
echo $headings[10];
echo $headings[11];
echo $headings[12];
echo $headings[13];
echo $headings[14];
echo $headings[15];
echo $headings[16];
echo $headings[17];
echo $headings[18];
echo $headings[19];
echo $headings[20];
echo $headings[21];
echo $headings[22];
echo $headings[23];
echo $headings[24];
echo $headings[25];
echo $headings[26];
$num = count($data);
echo "<p> <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c];
echo " ";
}
}
fclose($handle);
}
-
hi buzzycoder
that works a charm.
-
not much at all
-
which loop the while loop or the for loop as i want to capture the headings in variables, how would i do this
thanks
-
I have the follwoing code which basically opens up a spreasheet and displays the rows from a passed in csv file.
I there a way to get the headings of the spreasheet into variables?
thanks in advance
<?php
/**/
$newname = $_GET['newname']; //The file that has been moved into the Uploads/ folder will need to be stripped here to retreive just the filename...
$filename = basename($newname,"/"); //basename function strips off filename based on first forward slash "/"$row =3;
if (($handle = fopen($filename, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c];
echo " ";
}
}
fclose($handle);
}?>
-
it is coming from a directory
-
I have changed that and it still just shows the following output
/uploads/test_raw.csv
test_raw.csv
the Types variable is = Array
again here is the updated code
<?php
$newname = $_GET['newname']; //The Uploads/ folder will need to be stripped here to retreive the filename...
$filename = basename($newname,"/"); //basename function strips off filename based on first "/"echo $newname;
echo $filename;
// allowed file types here
$types = array(
'text/csv',
'text/plain',
'application/csv',
'text/comma-separated-values',
'application/excel',
'application/vnd.ms-excel',
'application/vnd.msexcel',
'text/anytext',
'application/octet-stream',
'application/txt',
);
echo "the Types variable is = " .$types;// initiate finfo() and get the file type of uploaded file
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->file($filename);echo "the Finfo variable is = " .$finfo;
echo "the Type variable is = " .$type;// check in array
if (!in_array($type, $types)) {
echo "file has an error ";
}?>
-
Hi Professionals
I am really struggling here. here is the whole code which may help. On the next page all that shows is
/uploads/test_raw.csv
test_raw.csv
the Types variable is = Array
then there is nothing else showing
<STYLE TYPE="text/css">
<!--
TD{font-family: Arial; font-size: 8pt;}
--->
</STYLE><?php include("header.php"); ?>
<!-- <?php include("footer.php"); ?> -->
<?php include("ConnectDB.php"); ?><?php
$newname = $_GET['newname']; //The Uploads/ folder will need to be stripped here to retreive the filename...
$filename = basename($newname,"/"); //basename function strips off filename based on first "/"echo $newname;
echo $filename;
// allowed file types here
$types = array(
'text/csv',
'text/plain',
'application/csv',
'text/comma-separated-values',
'application/excel',
'application/vnd.ms-excel',
'application/vnd.msexcel',
'text/anytext',
'application/octet-stream',
'application/txt',
);
echo "the Types variable is = " .$types;// initiate finfo() and get the file type of uploaded file
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->file($_FILES['file']['tmp_name']);echo "the Finfo variable is = " .$finfo;
echo "the Type variable is = " .$type;// check in array
if (!in_array($type, $types)) {
echo "file has an error ";
}?>
-
hi eliseth
I have
$filename = basename($newname,"/");
echo $filename which results in 'testfile.csv'
where does this come from
$type = $finfo->file($_FILES['file']['tmp_name']);
would this need to change to
$type = $finfo->file($_FILES['file']['$filename']);
?????
thanks
-
thanks for that but i do not understand that I have just put this on my page and tried passing through a pdf file and it still does show these when I echo them out it does not redirect back to my previous page either.
sorry once again but I am very new to php
$csv_mimetypes = array(
'text/csv',
'text/plain',
'application/csv',
'text/comma-separated-values',
'application/excel',
'application/vnd.ms-excel',
'application/vnd.msexcel',
'text/anytext',
'application/octet-stream',
'application/txt',
);if (in_array($_FILES['upload']['type'], $csv_mimetypes)) {
}$newname = $_GET['newname']; //The Uploads/ folder will need to be stripped here to retreive the filename...
$filename = basename($newname,"/"); //basename function strips off filename based on first "/" -
Hi Professionals
I have a ffile and folder name passed through as a variable as shown in the code below ready to import into a database, with thanks to (barand) in a previous post I have managed to strip this to retreive the filename only, see code below
$newname = $_GET['newname']; //The Uploads/ folder will need to be stripped here to retreive the filename...
$filename = basename($newname,"/"); //basename function strips off filename based on first "/"echo $newname;
echo $filename;
is there any way to check that this is a .csv file extension and if not redirect them back to the previous page
thanks in advance
-
fantastic that worked thanks
-
Hi professionals
I am passing a variable through to a page and it shows the filename and folder
$newname = $_GET['newname']; //The Uploads/ folder will need to be stripped here to retreive the filename...
echo "the filename is " . $newname;$sql = "exec importSAR " . "'" . "$newname" . "'";
exec importSAR 'uploads/output.csv'
I only want it to show the filename for my stored procedure
so it says
exec importSAR 'output.csv'
can this be done, can the uploads/ part be removed
thanks in advance
-
I used PBS's first reply and it worked, thanks
-
i am pretty new to php what do you mean by checking the extensions of $file
thanks
alan
-
Hi Professionals
I have the following piece of code that shows the files in a directory. What I want to to ias only show files of type .xls and xlsx
can this be done?
here is my code
<?php include("header.php"); ?>
<table width="100%" border="0">
<tr>
<td width="34%"> </td>
<td width="20%"> </td>
<td width="46%"> </td>
</tr>
<tr>
<td width="34%"> </td>
<td width="20%"><?php
echo "<form name=\"pickfile\" action=\"uploadedfile.php\">";echo "<select name='yourfiles'>";
$dirpath = "C:/inetpub/wwwroot/tocleanse/";
$dh = opendir($dirpath);while (false !== ($file = readdir($dh))) {
if (!is_dir("$dirpath/$file")) {
echo "<option value='$file'>" . $file . '</option>';
}
}
closedir($dh);
echo "</select>";
?></td>
<td width="46%"><?php echo "<button type=\"submit\" name=\"pickfile\">Upload File</button>\n";echo "</form>"; ?></td>
</tr>
</table>Thanks in advance
-
Hi Professionals
I have the following code which has taken ages to get right.
echo "<td><a href=" . $imagedir .">" ."<img src=" . $imagedir ."{$row['actual_image']} "."width=85 hight=50 border=0></img></a></td>";
this basically echos out the dirctory folder with the link to the image name as an href
what I want to do is be able to allow the user to make this bigger when clicked so it is readable
is this possible
-
now my url just shows
http://localhost/import1.php?uploads/ExtTypesTest.csv=uploads/ExtTypesTest.csv
in the import1.php page
and still shows "the filename is"
-
Hi Professionals
I have the following piece of code on my Upload page
<td width="33%" align="left"> <?php if ($result==1) header("Location: import1.php?$imagename"); ?></td>
which then goes to import1.php
in my browser address bar it shows http://localhost/import1.php?uploads/ExtTypes Test.csv
In my import1.php file i have the following code which shows nothing?
echo "the filename is " . $imagename;
Alll it shows is "the file name is"
any ideas?
thanks in advance
-
Hi Professionals.
I have a stored procedure in SQLServer 2008 which imports a csv file into the database.
Is there a way in php where i can execute this stored procedure by adding an upload button which runs my
EXEC importSAR procedure
Thanks in advance
Alan
-
any ideas anyone
-
The included file is in the same folder as my webpage. How do I find the included files path?
-
no that doesnt work, any other suggestions
-
Hi Professionals
I have the following php file which works and returns data from the database
<?php
$server='d3licsql02';
$connectinfo=array("Database"=>"TestData", "UID" => "sa", "PWD" => "secret");//connect to DB
$conn=sqlsrv_connect($server,$connectinfo);if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}$sql = "SELECT distinct software_manufacturer FROM softusecomp";
$stmt = sqlsrv_query( $conn, $sql);if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo "<option value=";
echo "'".$row['software_manufacturer']."'";
echo ">";
echo $row['software_manufacturer'];
echo "</option>";}
sqlsrv_free_stmt( $stmt);
?>
</select>
<input type="submit" value="Search">
</br></br>
</form>
</body></html>I have changed this to two seperate files below which do not work
<?php
include('ConnectDB');$sql = "SELECT distinct software_manufacturer FROM softusecomp";
$stmt = sqlsrv_query( $conn, $sql);if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo "<option value=";
echo "'".$row['software_manufacturer']."'";
echo ">";
echo $row['software_manufacturer'];
echo "</option>";}
sqlsrv_free_stmt( $stmt);
?>
</select>
<input type="submit" value="Search">
</br></br>
</form>
</body></html>ConnectDB.php
<?php
$server='d3licsql02';
$connectinfo=array("Database"=>"TestData", "UID" => "sa", "PWD" => "secret");//connect to DB
$conn=sqlsrv_connect($server,$connectinfo);if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}?>
Any Ideas
Execute stored procedure with the click of a button
in Microsoft SQL - MSSQL
Posted
figured it out thanks