Ghostscript: create extra folder for output JPEG - php

I have the following code:
<?php
$path = "/path/file/";
$pathout = "/path/out/file/";
exec('convert '.$path.'test_pdf.pdf[0] '.$path.$value.'.jpg');
?>
I want to know if there is a way that ghostscript generates the output JPG and at the same time also generates an new output folder?

I believe it can not.
Actually you are running a script. In Script, if the target directory does not exist, you will receive an error, like "Not a directory".

Ghostscript does not create directories, so no, it can't do that.

No, Ghostscript does not create new directories. It only creates new files. It can only write these files to existing directories.
It is the task of your script to prepare everything. Your script needs to create the new folder in advance where you want Ghostscript to write the output to.

Related

How to unlink file from children dir of parent dir? PHP

I want to unlink an image file from children dir of a parent dir.
I developing this project in a director folder under my website (mysite/project) but when i complete the project i will move to another hosting package.
Whic code i need use for stable running in all directories?
I get this error:
Warning: unlink(../../images/urunler/deneme-urun.jpg): No such file or directory in /home/admin/public_html/eticaret/admin/includes/updateproduct.php on line 120
My folder structure:
click here to see my folder structure
$delete = unlink("../../images/products/".$img);
Before running unlink() command you can check the existence of the file to get rid of such error
$path = "../../images/products/".$img;
if (file_exists(path)) {
unlink($path)
}
Better is using the full directory path (absolute path). An example, let your project structure is
and your unlinking code is in script.php, then your can get full absolute path the following way
$path = __DIR__ . "/../../images/products/{$img}";
if (file_exists(path)) {
unlink($path)
}
Thanks for all answers.
I have a fault on this topic.
Image name is xxx.jpg in my database but xxx.jpeg in the folder.
but there is an interesting situation: if you have an image as .jpeg format, you can open on browser as .jpg format.
I've tried a lot of methods to solve the above error, but I've found that.
I using chrome browser now.
So i solved my problem yet :)
as the script is run from "public_html/eticaret/admin/includes/" you need to .. traverse back 3 directories to get to public_html which is a common ancestor folder for both image and script
according to your directory image your images are in public_html/myproject/images/products/ and according to error detailed in your comment you are trying to delete from images/urunler/ I assume urunler is the actual project name.
if the folder containg your images is urunler try $delete = unlink("../../../images/urunler/".$img);
if the container folder is products try $delete = unlink("../../../images/products/".$img);
if that fails try using an absolute path instead of a relative path.

PHP/ImageMagick/Ghostcript: change output + input file paths

I have Ghostscript installed and ImageMagick (DLL).
The following PHP code works fine:
exec("convert test_pdf.pdf[0] $value.jpg");
But I want to read the PDF input from a different path (not from the location of PHP page).
I also want to write the output to a different path.
How do I do that?
You can create a variable for the different path and add it to your exec command:
<?php
$path = "/path/to/file/";
exec('convert '.$path.'test_pdf.pdf[0] '.$path.$value.'.jpg');
?>
You'll need to also make sure you have permissions set correctly for the new path in order to read/write from it using the exec command.

PHP UnRar.exe into a specific directory

Ive just found this script and it is exactly what im looking for, However how can i tell it to extract the files into a specific folder?
Here is the script
<?php
$winRAR = '"C:\Program Files\WinRAR\UnRAR.exe"';
$file="test.rar";
$do ="$winRAR e $file";
exec("$winRAR /?");
print_r($aOut);
exec($do,$aOut);
print_r($aOut);
?>
Im going to be extracting multiple files so i would like it to extract each archive into a a folder with the same name as the archive. So if the rar was called "Test" i want it to extract to a folder called /test/ and extract the files there?
Many Thanks in advance!
I suggest you to use the following command:
$do ="$winRAR x -ad $file $destinationPath";
Where $destinationPath is a destination path.
The "x" command will keep directory structure stored in archive in contrast with "e" command, which extracts files without subdirectories.
The "-ad" command line switch tells unrar to extract archive foo.rar to the $destinationPath/foo directory.
Command line commands and switches are listed in WinRAR help file, in section "Command line mode".
I think what you are trying to do may be easier using PHP's RAR extension. http://www.php.net/manual/en/book.rar.php

Location of a directory created with mkdir in PHP

I've been trying a bunch of stuff with creating zips and files and whatnot with php, and it's safe to say I messed up quite a few times...
My most recent:
$tmpp = tempnam('../test','mod');
echo "<br/>"."<br/>".basename($tmpp).'<br/>'."<br/>".$tmpp.'<br/>'."<br/>";
echo mkdir(basename('../test/'.$tmpp));
I meant to do
$tmpp = tempnam('../test','mod');
echo "<br/>"."<br/>".basename($tmpp).'<br/>'."<br/>".$tmpp.'<br/>'."<br/>";
echo mkdir('../test/'.basename($tmpp));
Oh well though, mistake is made. Where is this just created directory? How can I see all the other files and directories and things as well as the tmp folder?
edit: long story short: I've created a bunch of files and directories that I can't account for and I want to be able to find them on clean then off my server. How can I view ALL the files on my server, including in the tmp folder?
What's the return value of mkdir? "false" ?
If so, I think maybe you need check your write permisson of the account which execute this php script.

codeigniter creating a directory

How do I create a directory using codeigniter? Basically what I am trying to do is allow user to upload files and then create a directory on the fly for storing these file could anyone point me on how could I create a directory using codeigniter
Thanks
All efforts will be appreciated
I have run the following codes in windows which works perfect for me-
<?php
$path = "uploads/product";
if(!is_dir($path)) //create the folder if it's not already exists
{
mkdir($path,0755,TRUE);
}
?>
Here 0755 is permission of the folder to be created. 755 means you can do anything with the file or directory, and other users can read and execute it but not alter it. Suitable for programs and directories you want to make publicly available.
Use mkdir
mkdir("/path/to/my/dir");

Categories