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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Phrank
Forum Newbie
Posts: 6
Joined: Mon Sep 13, 2004 4:55 pm

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Phrank
Forum Newbie
Posts: 6
Joined: Mon Sep 13, 2004 4:55 pm

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

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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);
Post Reply