My apologies but this is a How to Question. I have limited knowledge of PHP and need figure out if PHP can do this
I have a list of video files that I need tagged with xspf files. And there are thousands of them all in the same directory!
How to make a PHP script read the video file names and create a text file with the video file name inside the text file with other pre-created text and then save the text file the same name as the video file(not the extension)
I searched and could only find a mp3 xspf generator but it creates one playlist of all the mp3 files it found in one directory.. I need to create a xspf file for each video(MP4) file in a directory - http://sourceforge.net/projects/php-xspf-gen/
Or if anyone knows of an windows App that can do the same...
Thank you..
I don't have any experience with xspf files, but creating a file for each video file is pretty easy.
$videoDir = 'C:/path/to/video';
$textDir = 'C:/path/to/textfiles';
foreach(scandir($videoDir) as $filename){
file_put_contents($textDir.'/'.$filename.'.txt', 'Text to put in file');
}
Some additional Code will be needed, but I hope this helps you in some way.
Related
I am extracting text from PDF files. this is the code:
<?php
require("PdfToText.php");
$file = 'SamplePF' ;
$pdf = new PdfToText ( "$file.pdf" ) ;
echo ( $pdf -> Text ) ;
?>
This class work fine for some PDF files.
The problem with this class is :
for some PDF files it take text from random page/line not in the
page sequence wise.
for some PDF files it is not showing any result.
for some PDF files it extract only one or two lines.
Please suggest some solution. Thank You!
I am not sure that this might be the exact problem because of which you are not able to extract but I also encountered something similar when extracting data from pdf. Sometimes the PDF files are locked by owner passwords which puts certain restrictions on the document and does not allow changing, content copying or extraction etc so as to protect its copyright issues. Check this link for more info on owner passwords.
So you can first try to remove owner password and then try to extract such pdf's. To remove owner passwords there are a number of tools available online, you can choose whichever fits you the best.
I currently have a problem to open a .ppt/.pptx file inside a webpage. I currently have all "uploaded" file in a folder and am able to open .html/.txt files in that folder, but not .ppt/.pptx. Whenever I try, a new window pops up and Windows Uploader starts to run.
<?php
$target_dir = "C:\Apache\htdocs\upload\\";
$target_file = $_FILES['file']['name'];
?>
<iframe src = "upload/"<?php echo $target_file; ?>" name = "iframe_s" id = "download" style = "display:none"></iframe>
Click here to view files
In the above code, I try to list all files in the folder, and the goal is a user can click on one of the file, then the file will open inside the webpage. The main problem I have right now is to have the program each individually attach different .ppt url to different files.
Thank you in advance!
For your question "How to upload to Google Docs".
My first Answer:Why don't you search properly???
If you still don't find it. Then, (taken from here)
You'd use the Google Documents API to upload them using a simple HTTP POST with the data. Here's an explanation how to upload and convert documents: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#UploadingDocs
The link will provide you will examples and all you need to do what you were asking for.
To be more precise this is what you are looking for if you want to upload pdf's: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#ResumableUploadPUT
Python Google Documents API guide
PHP Google Documents API guide
I need to find a certain key in a pdf file. As far as I know the only way to do that is to interpret a pdf as txt file. I want to do this in PHP without installing a addon/framework/etc.
Thanks
You can certainly open a PDF file as text. PDF file format is actually a collection of objects. There is a header in the first line that tells you the version. You would then go to the bottom to find the offset to the start of the xref table that tells where all the objects are located. The contents of individual objects in the file, like graphics, are often binary and compressed. The 1.7 specification can be found here.
I found this function, hope it helps.
http://community.livejournal.com/php/295413.html
You can't just open the file as it is a binary dump of objects used to create the PDF display, including encoding, fonts, text, images. I wrote an blog post explaining how text is stored at http://pdf.jpedal.org/java-pdf-blog/bid/27187/Understanding-the-PDF-file-format-text-streams
Thank you all for your help. I owe you this piece of code:
// Proceed if file exists
if(file_exists($sourcePath)){
$pdfFile = fopen($sourcePath,"rb");
$data = fread($pdfFile, filesize($sourcePath));
fclose($pdfFile);
// Check if file is encrypted or not
if(stripos($data,$searchFor)){ // $searchFor = "/Encrypt"
$counterEncrypted++;
}else{
$counterNotEncrpyted++;
}
}else{
$counterNotExisting++;
}
I have created a program which allows me to upload images to my server. They are given a random file name when uploaded. I want to be able to download all the images from a folder on the server so I can display them in my application. The only example I have seen requires that I know the file name of the images which I don't. How could I download all the images in a given directory (and store the downloads in an NSArray)? If there is no native way to do it does anyone know a way that it could be done via calling a PHP script? (I use a PHP script which the iPhone calls to upload the images).
Thanks.
To list all images in a directory using PHP and return a JSON encoded string:
$path = '/full/path/to/images/';
// find all files with extension jpg, jpeg, png
// note: will not descend into sub directorates
$files = glob("{$path}/{*.jpg,*.jpeg,*.png}", GLOB_BRACE);
// output to json
echo json_encode($files);
you can call a php script that will return the url for all of your images.
something like
yoursite.com/image123.jpg;yoursite.com/image213.jpg;yoursite.com/imageabc.jpg
then you parse the result, split by ";" and get the array of urls which you need to download.
HI
I have a forum and I'm trying to think of how to do an "attachment" feature.
You know if you make a thread you can chose to upload a file and attach it in the thread.
Should I make a table called attachment with id of the file id in table files?? Whats the best way. And I want you to be able to upload more than 1 attachment. and if it's a picture show a little miniature of the picture.
How should I check if the file exist etc? How would you do this?
Sorry for my poor english
You question is too broad but I'll give you some pointers:
store the images on the disk, something like /uploads/--thread_id--/1.jpg, /uploads/--thread_id--/2.jpg and so on (this way you don't have to make any changes to your DB)
Regarding the upload process, validation and image resizing you can read more at (I recommend you read them in this order):
http://pt.php.net/manual/en/function.exif-imagetype.php -> image validation
http://php.net/manual/en/function.move-uploaded-file.php -> upload process
http://pt.php.net/manual/en/book.image.php -> image resizing & manipulation
Chacha's plan sounds good to me, but you have to be careful. Make sure the files that you save don't have any execution permissions and that the file isn't on a web-accessible directory on your server. I think you should put the upload directory in a directory higher than your web directory for security purposes.
Another possible way to save the files: save their binary code in blobs in the database. I'm not sure if there are any advantages to this method, but I haven't personally had to deal with file uploads.
Above all else, be careful with uploaded data!
I honestly would create a Column on the table of posts that says 'Attachments', and then do a comma delimited string of attachment file names
file1.png,file2.png,file3.png
then when you get it into PHP, simply explode it
$attachments = explode(',', $string);
and check for each file that you have already put in your upload directory:
foreach($attachments as $file)
{
if(!is_file($upload_directory.$file))
{
$error[] = $file . " is not a valid attachment";
// run cleanup script
}
}
To get the attachments, it is really simple code, but you need to validate and sanitize the incoming file.
foreach($_FILES as $array)
{
// Sanitize Here
die("SANITIZE HERE!");
move_uploaded_file($array['tmp_name'], $upload_dir);
}