Trying to save a csv file on my server with codeigniter.
my syntax is:
$this->load->dbutil();
$query = $this->db->query("SELECT id,customeraccount,band FROM Customer_Bands");
$delimiter = ',';
$newline = "<br>";
echo $this->dbutil->csv_from_result($query, $delimiter, $newline);
if ( ! write_file(base_url().'/application/authorizations/test.csv', $this->dbutil->csv_from_result($query, $delimiter, $newline)))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
This is rough right now but want to get functionality working first.
Two issues.
Firstly the echo $this->dbutil->csv_from_result($query, $delimiter, $newline); outputs to my view correctly but each field is inside "", how can I remove these?
Secondly, the file is not writing to my server.
base_url() is my codeigniter root folder then inside applications I have created a folder named authorizations so base_url()/application/authorizations
This currently fails and echos 'Unable to write the file'
Thanks in advance
Related
Image path is getting stored in the database and file is getting uploaded in the upload path but the image is not displaying in the tabular format.
Here is the code for the view:
<tbody>
<?php
$query = $this->db->query("SELECT * FROM banner_mgmt LIMIT 1");
// $url = base_url().
foreach ($query->result() as $row)
{
echo "<tr>";
echo "<td>$row->id</td>";
echo "<td>$row->banner_name</td>";
echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
echo "<td>$row->banner_image</td>";
echo "</tr>";
}
?>
</tbody>
Assuming that base_url().$row->banner_image does actually result in a correct path/image name...
You need to check your string concatenation.
What you have... (overly complicated)
echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
What you should have...
echo '<td><img src ="'.base_url().$row->banner_image.'" style="height:150px; width:150px;" alt="not found"></td>';
You need to think about how you want the string to turn out, which helps you determine when and where to use ', " and . properly.
Here I am wrapping the string using ' (single quotes), which allows me to use " (double quotes) in the HTML properties without much effort.
Read up on how to use base_url() in the Codeigniter user guide...
So you could have
echo '<td><img src ="'.base_url($row->banner_image).'" style="height:150px; width:150px;" alt="not found"></td>';
You could even use " (double quotes) which evaluate php but you will need to escape any 'internal' double quotes you want to display.
echo "<td><img src =\"base_url($row->banner_image)\" style=\"height:150px; width:150px;\" alt=\"not found\"></td>";
So, you need to read the answer at What is the difference between single-quoted and double-quoted strings in PHP?
I am trying to upload a video file with my controller as below
Controller
if(Request::hasFile('file1')){
echo "Yes, file";
exit;
$file = Request::file('file1');
$filename = $file->getClientOriginalName();
$path = public_path().'/uploads/';
return $file->move($path, $filename);
} else {
echo "No file";
exit;
}
When i submit my a JPG/PNG file, it echo "Yes, file" i.e the file exist but when i submit an MP4 video, the file isn't found..
What could be the issue please ? Is there a particular way of sending Mp4 to my server in Laravel ?
The issue here can be your php configuration in php.ini regarding the max allowed size of the uploaded file.
post_max_size
upload_max_filesize
I am facing a small problem.I need the absolute path of Mage.php file in app folder.
I am using /pinktaff.u1163.cartikahosting.com/app/Mage.php in wordpress plugin "mage enabler"
but it is showing invalid..Can anyyou please help me out.
More than likely /pinktaff.u1163.cartikahosting.com is not the full path to your document root
In magento create a blank php file in the site root and add the code below
<?php echo $_SERVER['DOCUMENT_ROOT']; ? >
See http://www.seomad.com/SEOBlog/find-out-the-root-path-on-your-server-in-php.html
Or
dirname(__FILE__)
see http://php.net/manual/en/function.dirname.php
You could also test to see if the path is correct by doing
<?php
$filename = '/pinktaff.u1163.cartikahosting.com/app/Mage.php';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
I need to make a web site on which people can upload data files that after some treatment will be plotted using the jpgraph. The file is analyzed with a bash script called analfile.sh. The bash script is like this:
#!/bin/bash
file=$1
fecha=`date +%s`
mv $1 $fecha.dat
echo $fecha.dat
So, it gives back another file which name is like: 1321290921.dat. That is the file that I need to plot.
This my current php code:
$target_path = "/home/myhome";
$target_path = $target_path . basename( $_FILES['rdata']['name']);
$target_file = basename( $_FILES['rdata']['name']);
if(move_uploaded_file($_FILES['rdata']['tmp_name'], $target_path)) {
echo "The file ". $target_file. " has been uploaded";
chdir('/home/myhome');
$filetoplot=shell_exec('./analfile.sh'.' '.$target_file);
} else{
echo "There was an error uploading the file, please <a href=\"index.html\">try again!
</a>";
}
//$filetoplot="1321290921.dat"
echo "<br>The file to be opened is ". $filetoplot. "<br>";
if ($file_handle = fopen("$filetoplot", 'r')) {
while ( $line_of_text = fgets($file_handle) ) {
$parts = explode('.', $line_of_text);
echo $line_of_text ;
print $parts[0] . $parts[1]. $parts[2]. "<br>";
}
fclose($file_handle);
}
I have permissions to read and write on the target directory. I find strange that if I uncomment the line $filetoplot="1321290921.dat" then the script works perfectly. I guess I am doing something stupid since this is my first code in php but after some hours googling I was not able to find a solution.
Any help will be appreciated.
First thing I'm seeing is that you don't append trailing slash (/) to your home path, so that the path would be like /home/myhomefoo rather than /home/myhome/foo.
You should also move $target_file earlier, and reuse that within $target_path. There's no reason to do the same thing twice.
If that doesn't help, we'll see what goes next.
My MediaWiki cannot get the path of my live web server. Here is the code:
$script = $_SERVER['SCRIPT_NAME'];
$path = pathinfo( $script, PATHINFO_DIRNAME ) . '/';
$path = str_replace( '//', '/', $path );
$ext = pathinfo( $script, PATHINFO_EXTENSION );
echo "Please enter";
The localhostwebserver displays the echo as: Please enter,
but the live server displays the echo as Please enter
How is that possible? Need help!
If you need the url of the current page in php, I can recommend this script. I have used it successfully for years.