Jump to content

File System


mssakib

Recommended Posts

Hi

 

i am using ghost script to make images from PDF. and i have made like this that i will upload a pdf file and after upload it would automatic convert that into images. But having a problem . My script Generates images from all pdf file avail in directory .

 

I am using like this

 

$inputPDFFileName ="upload/*.pdf";
$cmd = "some commands.....";
$response = shell_exec($cmd);

 

I know you would say that it generates because of *.pdf but how to fix  that.

 

Should i use something like this for each file as file.... or whatever.

 

need some help:)

Link to comment
Share on other sites

The code i used to convert all of files into images

 

<?php require_once('Connections/hammad.php'); ?>
<?php 
mysql_select_db("bakery") or die(mysql_error());
$id=$_GET['id'];
$image =  mysql_query("SELECT img FROM pic WHERE `Desc`='".$id."'") or die(mysql_error());
$image = mysql_fetch_assoc ($image);
$image = $image ['img'];
header("content-type: image/jpg");
echo $image;
?>

Link to comment
Share on other sites

OP, are you image names stored in a mysql table?

 

Probably not, if he just said he does not want to use SQL. And as mentioned already if you don't want all the pdf files to be converted you need to create some method to define the pdf files you want to convert. Maybe a select, maybe a search or something. Then put the files into array and convert the wanted pdf files only just like you do when you convert all the files in dir.

Link to comment
Share on other sites

Alright, I thought you did but didn't want to use it for some reason, sorry I misunderstood.

 

However I still stand by the my first reply, a pattern that your files must follow is needed...

 

such as, then you can loop through it with an iteration.

 

filename_1.pdf

filename_2.pdf

filename_3.pdf

 

 

Link to comment
Share on other sites

Apparently it isn't solved.

 

If you want to use Database then I suggest you store all of your files in a table

 

file_tbl
-----------
id - int(11) unique
file - varchar(225)
filepath - varchar(225)
dateposted - datetime

id | file               | filepath                | dateposted
-------------------------------- -----------------------------
0 | file.pdf         | upload/                | YYY-MM-DD HH:MM:SS
1 | abc.pdf        | upload/                | YYY-MM-DD HH:MM:SS
2 | sum1.pdf     | upload/                | YYY-MM-DD HH:MM:SS 
3 | lol.pdf          | upload/                | YYY-MM-DD HH:MM:SS
4 | php.pdf        | upload/                | YYY-MM-DD HH:MM:SS
5 | upl.pdf         | upload/                | YYY-MM-DD HH:MM:SS
6 | 111.pdf        | upload/                | YYY-MM-DD HH:MM:SS

 

Now you can do this

 

 


$query = mysql_query("SELECT `id`,`file`,`filepath`FROM `file_tbl` ORDER BY `dateposted` DESC") or die(mysql_error());
while($row = mysql_fetch_fetch_array($query)){
$inputPDFFileName = $row['filepath'] . $row['file'];
$cmd = "some commands.....";
$response = shell_exec($cmd);
}

 

Link to comment
Share on other sites

Yap going good. During each upload it saves those data in sql. I also gave each a unique ID .

Now a little problem is . How call that filename from sql and give the generated file a unique name. Like this

 

 

$filePath= "upload/ I want here the filename from sql": // Do i need to use mysql_query ?

 

and then

shell_exec( gs -sDEVICE=jpeg -sOutputFile=s_%d.jpg -dSAFER -dBATCH -dNOPAUSE -r100×100 $filePath); //-sOutputFile=s_%d.jpg = File name and  %d    will generate name according to page num.

 

But here is a problem suppose i have a pdf file named s.pdf and from it it generates S_1.jpg and when  i put another pdf ... it removes my previous image and also names it as s_1.jpg. So how to give the -sOutputFile a unique name each time ?

 

thanks a lot helping. Learning php is interesting :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.