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
Related
How can i get all text and sentences (content) from laravel.log file?
this below code is not working for me :
error_reporting(E_ALL);
$logs = fopen("storage\logs\laravel.log", "r") or die("Unable to open file!");
echo fread($logs, filesize("laravel.log"));
fclose($logs);
return response()->json($logs);
and my error :
fopen(storage/logs/laravel.log): Failed to open stream: No such file or directory
Thank you for your guidance.
Access using
$logPath = storage_path().'/logs/laravel.log';
$logs = fopen($logPath , "r") or die("Unable to open file!");
And make sure laravel.log exists.
I want to move all images up 1 folder after which I can remove the empty folder but I always get the error "File already exists at path: public/images"
$files = Storage::files('public/images/'.$dir->name);
foreach($files as $file){
Storage::move($file, 'public/images');
}
Storage::deleteDirectory('public/images/'.$dir->name);
$dir->delete();
The files that I wanted to remove don't exist in the public/images directory. So why do I get the error "File already exists at path: public/images"?
This should solve your problem.
$files = Storage::files('public/images/'.$dir->name);
foreach($files as $file){
Storage::move($file, 'public/images/'.basename($file));
}
Storage::deleteDirectory('public/images/'.$dir->name);
$dir->delete();
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
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.