This gives a Warning Message: filesize(): stat failed for http://localhost/wft/uploads/4_Sat_Sep_10_2016_16_18_52.pdf
$file_path = base_url().'uploads/4_Sat_Sep_10_2016_16_18_52.pdf';
$size = filesize($file_path);
how to find file size of pdf.
You could do this without using the URI, instead using the path to the File.
<?php
// CHANGE __DIR__ TO FIT WITH THE PATH TO THE ROOT DIRECTORY HOLDING THE PDF FILE
$file_path = __DIR__ . '/uploads/4_Sat_Sep_10_2016_16_18_52.pdf';
$size = filesize($file_path);
PHP filesize() function give the file size.
$path = "uploads/your_file";
$size = filesize($path);
NB: Path should be a relative path.
Related
//Image present in my db after the upload script is executed but not in the root directory. The script have been working well in my previous projects but fails to work here.
//upload script
$file = $_FILES['file']['name'];
$dir = 'picture/';
move_uploaded_file($_FILES['file']['tmp_name'],$dir);
$new_name = rand(10,1000);
$new_name .= $file;
rename($dir,'picture/'.$new_name);
$new_name = 'picture/'. $new_name;
//error
Warning: rename(picture/,picture/424) [function.rename]: Permission denied in C:\wamp\www\Transact\signedup.php on line 87
You must use $dir/$file in rename to point to the source file. In your code, you were renaming the directory not the file.
Also keep using $dir instead of using hardcover value 'picture/'
$file = $_FILES['file']['name'];
$dir = 'picture/';
move_uploaded_file($_FILES['file']['tmp_name'], "$dir/$file");
$new_name = rand(10,1000);
$new_name .= $file;
rename("$dir/$file" ,$dir.$new_name);
$new_name = $dir. $new_name;
How can i get the file size of a file stored in the storage folder? $fileFullPath leads to correct path but $size = Storage::size($fileFullPath) fires the exception: File not found at path.
public function getFromStorage()
{
$contents = Storage::disk('local')->get('txtFiles/file.txt');
$fileFullPath = Storage::disk('local')->path('txtFiles/file.txt');
$size = Storage::size($fileFullPath);
dd( $fileFullPath) // return correct path
dd( $size) // return file not found
}
size($file) does not expect the full path, but the relative path. Try:
$size = Storage::disk('local')->size('txtFiles/file.txt');
Program to load pdf image and at the same time convert them to jpg using Imagick.But couldnt convert and load it in Destination directory.
$name = $_FILES['file']['name'];
$fileName = substr($_FILES['file']['tmp_name'], 5).".".$ext;
date_default_timezone_set('UTC');
$fileDate = date('d.m.Y');
$fileSize = $_FILES['file']['size'];
$folder = $_POST['folder'];
$uploadfile1="$media_dir/$fileName";
$imagick = new imagick();
$imagick->readImage($uploadfile1);//line 149
$imagick->setImageFormat('jpg');
foreach($imagick as $i=>$imagick)
{
$imagick->writeImage($uploadfile1. " page ". ($i+1) ." of ". $pages.".jpg");
}
Error
Fatal error: Uncaught ImagickException: unable to open image
`/opt/ama/mediaFiles/phpe765pr.pdf': No such file or directory #
error/blob.c/OpenBlob/2701 in
/home/james/workspace/ama/1.1/userinterface/webfleet/gui/ama/modules/mediaFiles/uploadFile.php:149Stack
trace:#0
/home/james/workspace/ama/1.1/userinterface/webfleet/gui/ama/modules/mediaFiles/uploadFile.php(149):
Imagick->readimage('/opt/gpssi/medi...')#1 {main} thrown in
/home/james/workspace/ama/1.1/userinterface/webfleet/gui/gpssi/modules/mediaFiles/uploadFile.php on line 149
You have a problem with the path of
/opt/ama/mediaFiles/phpe765pr.pdf
Make sure the path exists and the necessary privileges are given to all the folders in the path along the file to read it.
Trying to get a pdf document file size, but it is giving me Warning: filesize(): stat failed for...
What I have tried:
//get original temporary name
$temp_name = $_FILES['userDegreeFile']['tmp_name'];
//original file path with original name
$inital_name = $_SERVER['DOCUMENT_ROOT'] . "super/IMG/user_files/user_files_".$userFirstName."_".$user_id."/" . $temp_name;
//get the file size
$file_size = filesize($inital_name);
When running this I get the error stated above. The file name in the error is D:/Programs/wamp/www/super/IMG/user_files/user_files_Jim_52/D:\Programs\wamp\tmp\php70B9.tmp
What am I doing wrong?
Always use DIRECTORY_SEPARATOR, its compatible for both linux and windows path.
$inital_name = $_SERVER['DOCUMENT_ROOT'] . "super".DIRECTORY_SEPARATOR."IMG".DIRECTORY_SEPARATOR."user_files".DIRECTORY_SEPARATOR."user_files_".$userFirstName."_".$user_id.DIRECTORY_SEPARATOR."$temp_name;
Another way is $_FILES ["file"]["size"]; Check here for more info : How to use $_FILES["file"]["size"]?
Please try this I think this will help you
`
// outputs e.g. somefile.txt: 1024 bytes
$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filenam`) . ' bytes';
?>
`
i am getting an error in uploading image into folder. there is an error occured during uploading that image.
my Controller Code is (cakeplus is my root folder ex: htpp://localhost/cakeplus) :
$directory = "http://".$_SERVER['HTTP_HOST'].'/cakeplus/pics';
if(!is_dir($directory)) {
mkdir($directory,0777);
}
$files_array = $this->data['Photo']['path'];
//pr($files_array); die;
if(isset($files_array['name']) && $files_array['name']!='') {
$filetype = $files_array['type'];
$filesize = $files_array['size'];
$filename = $files_array['name'];
$filetmpname = $files_array['tmp_name'];
$file_type = explode('.',$filename);
$ext_name = array_reverse($file_type);
$final_file_title = $ext_name[1];
$file_name = Inflector::slug( str_replace( ".".$ext_name[0], "" , $filename ). '_' .time() ,'-' );
$newFileName = $file_name.'.'.$ext_name[0];
move_uploaded_file($filetmpname, $directory.'/'.$newFileName);
$requirementuploadData['Photo']['path'] = $file_name;
$this->Photo->create();
$this->Photo->save($requirementuploadData,false);
}
Error(s)(Warnings) :
Warning (2): move_uploaded_file(http://localhost/cakeplus/pics/wallpaper-1433586197.png): failed to open stream: HTTP wrapper does not support writeable connections [APP\Controller\PhotosController.php, line 31]
Warning (2): move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpA80D.tmp' to 'http://localhost/cakeplus/pics/wallpaper-1433586197.png' [APP\Controller\Photos
Look into the CakePHP Upload plugin - it will abstract away much of the work that goes into dealing with file and image uploads.
The error you are seeing is because you cannot use move_uploaded_file() to transfer from a file path (C:\xampp\tmp\phpA80D.tmp) to an HTTP URL (http://localhost/cakeplus/pics/wallpaper-1433586197.png).
If you don't want to use the Upload plugin, and would prefer to keep working with what you already have, I would start by changing the $directory path. Something like this might be more appropriate:
$directory = WWW_ROOT . 'pics';
This will contain the path to your ./yourapp/webroot/pics directory, which is also the location of http://yourapp.com/pics.
Check out the documentation for more predefined paths.
may be folder dont have permission to write an image.
you should to use cakephp upload component.
$this->Upload->upload($file,$destination,$name);