Page 1 of 1

In general how to you save an image that is in a var?

Posted: Tue Sep 14, 2004 5:45 pm
by Phrank
I have a jpeg image in a mysql db. I want to save that image to disk. Is there a command that copies a db field to a file on the disk or do I need to create new patette and then use imagecratefromjpeg()?

Surely there is a function to save a file to disk from a var.

Posted: Tue Sep 14, 2004 5:58 pm
by feyd
put the stored image into a variable, [php_man]fopen[/php_man] and [php_man]fwrite[/php_man] the variable. You could use [php_man]file_put_contents[/php_man] if you are running php5.

Thanks - I can't seem to be able to do this on the server.

Posted: Tue Sep 14, 2004 10:52 pm
by Phrank
After some reading I was able to create a directory with high enough permissons on my XP mach running IIS. Here is the code I used:

Code: Select all

<?
umask(011); 
mkdir('Temp', 0777); 
?>
Temp is in the right place and I can fopen() to it without any problems. Thanks.

I need to do that now on the web hosting services web server. Fatcow.com.

When I run the above code on the web server it does not give me an error but does not create a Temp dir. I view the dir's via FTP.

When I called the web service they said to use FTP to create a dir and then right click on it via FTP and up the permissions to write and execute for all - which I did.

Still cannot do an Fopen() to a file in that dir. Just can't write to it even tho I gave the dir all the permissons I could.

Any Ideas? Where the dir "Temp" that seemed to be created on the web server?

How do I give the dir I created - high enough permissons on the web server?

Can I use umask on a dir that I created on the web server. I know nothing about unix.

I am sure if I can get past permissions I will have it beat.

Thanks for your help

Frank

PS. Here is the script I am using to create the Test.jpg with fopen()

Code: Select all

<?
//$OrgFileName = ".\\MyImages\\test.jpg";
$OrgFileName = "Temp\\test.jpg";
//$OrgFileName = "c:\\Inetpub\\wwwroot\\Kinders\\MyImages\\Test.jpg";

$handle = fopen("test.jpg", "wb");
echo "handle=" . $handle;

?>
Works fine on my XP mach but not the web hosting server.

Posted: Wed Sep 15, 2004 12:26 am
by Weirdan
  • In the unix world we are using forward slash ('/') to separate directories in the path strings
  • fopen expect its first argument to be either full or relative path to the file being opened
  • Please use

    Code: Select all

    tags when posting code[/list]
    thus:

    Code: Select all

    $content = 'whatever';
    mkdir('test');
    $fh = fopen('test/test.jpg', 'wb') or die("Can't open file");
    fwrite($fh, $content);