Recovery Symfony2 session - php

I am a beginner in PHP and am working on a web application developed in Symfony 2, in this application I built a flash module that records the sound of the microphone and save the mp3 file to the connected account folder.
(each user must be connected for it to make recording)
here is my code which is used to save the mp3 file to a folder (recording / user1)
<?php
$songname = $_GET["name"];
$filename = $songname. " - " . date("dmY"). ".mp3";
$file = "recording/" . $filename;
$songname $_GET["name"];
$putdata = fopen("php://input", "r");
$fp = fopen($file, "w");
while ($data = fread($putdata, 1024))
fwrite($fp, $data);
fclose($fp);
fclose($putdata);
echo $filename;
}
?>
My question: If possible, please retrieve the session or the name and user name connected and send the mp3 file directly to each user's folder (folders are created in advance in the recording folder).
thank you

Related

how to download users twitter images from API with php

i am trying to download twitter users images that sign up in my website such that i can save them in my file to insert into my database later on for use in my website.
this is my TWITTER API:
$user_pic = $user_info->profile_image_url_https;
i tried this and it works but i want it to download the image to my base file which is profilePictures/:
$twitterimage = file_get_contents($user_pic);
$fp = fopen('path_to_filename.png', 'w');
fwrite($fp, $twitterimage);
fclose($fp);
now it is being downloading but how can i download the twitter images and save them in my base file "profilePictures/"?
i found the solution, all i had to do is this
$user_pic= str_replace('_normal','',$user_pic);
$Imgurl = $user_pic;
$target_path = "profilePictures/";
$filename = basename($Imgurl);
$saveLoc = $target_path . $filename;
file_put_contents($saveLoc, file_get_contents($Imgurl));
and then save the $saveLoc variable into my database

How can i Download file to local directly from Dropbox API

I m using https://github.com/kunalvarma05/dropbox-php-sdk this library in my laravel project .From this code this "example.txt" file downloaded in my project directory. But i want to download this "example.txt" file with my browser into browser download folder.
$file = $dropbox->download("/example.txt");
$contents = $file->getContents();
$metadata = $file->getMetadata();
file_put_contents(__DIR__ . "/example.txt", $contents);
A little use with Google and found it for you.
$file = $dropbox->download("/my-logo.png");
//File Contents
$contents = $file->getContents();
//Save file contents to disk
file_put_contents(__DIR__ . "/logo.png", $contents);
//Downloaded File Metadata
$metadata = $file->getMetadata();
//Name
$metadata->getName();
link to examples and github:
https://github.com/kunalvarma05/dropbox-php-sdk/wiki/Upload-and-Download-Files

Trying to find file extension on hidden download url

I am trying to make a script to take a downloadable file and put it onto my ftp server to then update a database. I cannot figure out what the url extention should be to able to make this work.
<?php
$src = fopen('https://www.atf.gov/firearms/docs/0516-ffl-listxlsx/download', 'r');
$dest1 = fopen('first1k.xlsx', 'w');
$dest2 = fopen('remainder.xlsx', 'w');
echo stream_copy_to_stream($src, $dest1, 19759460) . " bytes copied to first1k.txt\n";
echo stream_copy_to_stream($src, $dest2) . " bytes copied to remainder.txt\n";
?>
This is where I am trying to get the data from https://www.atf.gov/firearms/listing-federal-firearms-licensees-ffls-2016
<?php
$file = "0516.xlsx";
$url = 'https://www.atf.gov/firearms/docs/0516-ffl-listxlsx/download' ;
$handle = fopen("0516.xlsx", "w+");
fwrite($handle, file_get_contents($url));
rewind($handle);
$read = htmlentities(fread($handle, filesize($file)));
?>
fixed it out

How to save images from list image url in csv

I want to save images from url to my directory and its image name after downloaded into a csv.
I write the following code which store images. but its not working as I want.
in below code $img is variable which fetch url from csv.
suppose I have 1000+ products in csv and every products have image url like
www.example.com/images/image1.jpg
so I want to download this image to my local directory/server directory and store its image name after download to csv file so I can add only image name into database tables.
set_time_limit(1000);
while($url = $response->fetch()) {
$my_image = file_get_contents($img);
$my_file = fopen('/csvfiles/','w+');
fwrite($my_file,$my_image);
fclose($my_file);
}
The some solution I found on other similar questions is
$file = file_get_contents($img);
file_put_contents("/csvfiles/Tmpfile.zip", fopen($img, 'r'));
But it is not applicable in my condition or not working.
Any help would be appreciated.
Edit New -
As marked as duplicate I want to add some more info here -
As I have all products info in csv formats and while importing the products I also want to download images from its url. And it is not possible to download 1000+ product image manually. I checked the above solution but it is not applicable in this situation. As in above solution they download image from only particular page and rename it directly. so it is different scenario here.
New Code - I also tried this code still not working
$content = file_get_contents("http://www.google.co.in/intl/en_com/images/srpr/logo1w.png");
$fp = fopen("/csvfiles/image.jpg", "w");
fwrite($fp, $content);
fclose($fp);
Try with the following code.
set_time_limit(1000);
while ($url = $response->fetch()) {
$my_image = file_get_contents($img);
// check stricly that you have content of image
if ($my_image !== false) {
// download the image and store in the database.
$my_file = fopen('/csvfiles/', 'w+');
fwrite($my_file, $my_image);
fclose($my_file);
}
}
You need a filename as well, not only a directory:
// download the inage from the internet:
$my_image = file_get_contents($url);
// get filename from url:
$filename = basename($url);
$path = '/csvfiles/' . $filename;
// save image to that file:
$my_file = fopen($path,'w+');
fwrite($my_file, $my_image);
fclose($my_file);
// save $filename to DB
Hi below code works for me .. hope it will help someone..
Thanks #Gavriel and #Alankar
if(!empty($img)){
$my_image = file_get_contents($img);
file_get_contents(filename)
$filename = $data[0] . ".jpg";
echo $filename. "\n";
if(!file_exists($filename))
{
$my_file = fopen($filename,'w+');
file_put_contents($filename, $my_image);
echo $filename . "\n";
}
}
$image = "/uploads/" . $filename;
echo $image . "\n";
Here $img store url of image. which is fetch from csv file.
Here data[0] is csv column which is used to store image name uniquely . so we can use file_exists(); otherwise whenever I run my script again and again it store images again and store it by random temp name.

PHP upload text to file

I am after some help with some code for a HTML feature.
I am wanting to get information from two textboxes on a web site (txtName,txtBody), and then save the contents of these textboxes to a file on an ftp server using PHP.
Can someone point me in the correct direction to do this?
thanks
File put contents can be used to accomplish this as dagon says, below is a simple example.
<?php
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
//Assign txtName to variable.
$name = $_POST['txtName'];
// Append a new person to the file
$current .= $name;
// Write the contents back to the file
file_put_contents($file, $current);
?>
If you dealing with ftp then you have to use http://www.php.net/manual/en/function.ftp-fput.php
$file = $_POST['txtName'];
file_put_contents($file, $_POST['txtBody']);
$fp = fopen($file, 'r');
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
ftp_close($conn_id);
fclose($fp);

Categories