How to get file extension from a uri of Drupal 7 - drupal-7

I have file uri {s3://video-seven-test/file_name.mp4} how do I get the extension from this uri?

See http://php.net/manual/en/function.parse-url.php to parse the URL to get the proper path and http://php.net/pathinfo to get the extension from the path

$file = file_load($fid);
$path = drupal_realpath($file->uri);
$parts = pathinfo($path);
$extension = $parts['extension'];
thanks to nmc

Related

How to extract tiff files of a range the URL with zipfiles?

I want to extract the tif file from a range of URL. This code works for one zip file, but if I want to extract zips in a range(1,43) it doesn't work
the error is:
BadZipFile: File is not a zip file
Could somebody help me?
print('Downloading started')
for number in range(1,3):
url = f'https://downloadagiv.blob.core.windows.net/dhm-vlaanderen-ii-dsm-raster-1m/DHMVIIDSMRAS1m_k{number}.zip'
req = requests.get(url)
# Split URL to get the file name
filename = url.split('/')[-1]
req = requests.get(url)
print('Downloading Completed')
zipfile= ZipFile(BytesIO(req.content))
listOfFileNames = zipfile.namelist()
for filename in listOfFileNames:
# Check filename endswith tif
if filename.endswith('.tif'):
# Extract a single file from zip
zipfile.extract(filename, '/content/gdrive/My Drive')

Uploading and storing file with Laravel

I am using Laravel illuminate/html and I am trying to upload an image file and store it in /public in the laravel installation folder. I have got the image from the request:
$img = Request::file('img');
How can I store it in the public folder?
Thanks
You could do this in your controller:
Request::file('img')->move(base_path('public/uploads'));
Or if you wish to specify a generic filename or change filename
$newfilename = str_random(32) .time();
$ newfilename = $newfilename. ".". Request::file('img')->guessClientExtension();
Request::file('img')->move(base_path('public/uploads'), $newfilename);`

Get paths for the Magical Record store files

Getting Cocoa error 260, which says file not found.
NSArray *inputPaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[[[NSPersistentStore MR_defaultLocalStoreUrl]absoluteString]stringByDeletingLastPathComponent]error:&folderError];
if (folderError) {
[SVProgressHUD showErrorWithStatus:folderError.localizedDescription];
}
Why? Or is it any other way to get store files paths?
Found an answer here:
NSURL path vs absoluteString
absoluteString is for the remote urls only, for local file urls should be used path instead.

C# .NET - Read a csv file from URL and open it in the browser with Save and open button options

I have a URL to the csv file and I need a code in C#.net to read the file from this url and open it in the browser..basically allow an option for save and open. I am trying to use System.Net.WebClient
Can anyone pls help on this..Thanks in advance
Haven't done that in a long time (before .net actually), but the recipe was :
//grab the csv file
var wc = new System.Net.WebClient();
var fileContent = wc.DownloadString("your url here");
// Clear and set the headers accordingly to the desired action
Response.ClearHeaders();
Response.AddHeader("Content","text/plain");
// send the data and say goodbye
Response.Write(fileContent);
Response.Flush();
Note that I'm most certainly wrong on the mime-type settings, but you should find that easily.

CakePHP saving thumbnail image error (unable to open)

I am using WebTechNick's file upload plugin to save images on my CakePHP site. That part is working perfectly. I am working in my projects_controller in the add action I loop through the uploaded files and attempt to create and save thumbnails. The thumbnail creation goes well, but I get this error when trying to save the images to the thumbnail directory.
Unable to open 'files/project_images/thumbs' for writing: Is a directory
my files, project_images, and thumbs are all chmoded to 777 so I dont see why I am getting an "unable to open" error. My full code is below.
for($i=0; $i<=2; $i++){
$path = 'files/';
$imageName = $this->Project->Image->read('name', $imageStartingId);
$fullPath = $path . $imageName['Image']['name'];
list($width, $height) = getImageSize($fullPath);
$ratio = $width/$height;
$thumbnailHeight = $thumbnailWidth/$ratio;
//resample
$imageThumb = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
$image = imagecreatefromjpeg($fullPath);
imagecopyresampled($imageThumb, $image, 0,0,0,0, $thumbnailWidth, $thumbnailHeight, $width, $height);
imagejpeg($imageThumb, 'files/project_images/thumbs', 100);
$imageStartingId--;
}
any help is much appreciated. Thanks!
You need to give imagejpeg() a filename, and you've given it only the path, as the error message says. Change it to
imagejpeg($imageThumb, 'files/project_images/thumbs/'.$imageName['Image']['name'], 100);
or whatever you want the filename to be.

Resources