I’m working on a project which downloads a video from youtube and converts it to mp3.
Its all on the command line and no forms or anything.
I want to upload the mp3 to the server and send its path to db.
So, I’ve tried this method for uploading the file.
The file upload returns successful but I can’t find any file in uploads/.
I don’t know even if the file has been uploaded or not.
I’m super confused and have been searching the net for 3 hrs now with no results.
Here Is my code. Please have a look.
$target = 'uploads/';
$ch = curl_init('http://localhost/Song%20Downloader/upload.php'); // Dont know what to pass the url here.
curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => array(
'files[]' => '@$videoTitle.mp3', // the mp3 file is saved with the name of video title.
),
));
if (false === ($res = curl_exec($ch))) {
die("Upload failed: " . curl_error($ch));
} else {
echo " Upload Successful :D";
move_uploaded_file ( $videoTitle , $target);
}
Any help will be appreciated.