This topic is locked

Storing an image

7/17/2007 8:46:25 AM
PHPRunner General questions
D
dcrera author

Hi,
How do I limit the image to be stored for a specific file type eg .jpeg, .bmp etc

when the browse button is pressed ?
Thanks

J
Jane 7/17/2007

Hi,
you can put this checking into generated include\commonfunctions.php file.

Find this line there:

$file_move = array($file['tmp_name'],GetUploadFolder($field).$value);


and put your checking just after.

Here is the sample code:

if($file["size"]>2048*1024)

return false;

$ext = substr($file["name"], strlen($file["name"])-4);

$ext=strtoupper($ext);

if($ext!=".JPG" && $ext!="JPEG" && $ext!=".BMP")

return false;

D
dcrera author 7/18/2007

Hi.
How to I reference the field value next to the browse button.
ie the file name to upload eg E0012142.bmp
Thanks

Hi,

you can put this checking into generated include\commonfunctions.php file.

Find this line there:
and put your checking just after.

Here is the sample code:

M
mmponline 7/18/2007

Is there a way to limit Mb size instead of pixels with similar code.
Also: Can it display a message. Eg. "Sorry, file to large, please resize first".
I also found a small photo resizer (freeware) that can be made available to clients to resize pics without needing fancy software.
Maybe there is something better or even an online app.
I use: Photo Resize Magic 1.1. Can do single photo or whole folders/ sub-folders and keeps aspect ratio.
http://www.realfiletools.com/free/photorm.zip

J
Jane 7/18/2007

Stephan,
to limit size of the uploaded file use following code:

*if($file["size"]>20481024)

return false;

**

$ext = substr($file["name"], strlen($file["name"])-4);

$ext=strtoupper($ext);

if($ext!=".JPG" && $ext!="JPEG" && $ext!=".BMP")

return false;


To show message on the page use Before record added or Before record updated event on the Events tab.

Here is a sample code:

if ($_FILES['file_FieldName']['size']>2048*1024)

echo "file > 2mb";

D
dcrera author 7/18/2007

Hi Jane,
I tried this code and it does not seem to work
$file_move = array($file['tmp_name'],GetUploadFolder($field).$value);

$files_move[] = $file_move;

return $value;
if($file["size"]>20481024)

return false;
$ext = substr($file["name"], strlen($file["name"])-4);

$ext=strtoupper($ext);

if($ext!=".TIF")

return false;
In the Before Record is added
if ($ext != ".TIF")

{$error = 1;

echo "Invalid file type, must be
.tif";}
error message is
Undefined variable: ext
Thanks

Stephan,

to limit size of the uploaded file use following code:
To show message on the page use Before record added or Before record updated event on the Events tab.

Here is a sample code:

D
dcrera author 7/18/2007

Also, how do I get around to save large files of 4000 kb +/-
Thanks

Hi Jane,

I tried this code and it does not seem to work
$file_move = array($file['tmp_name'],GetUploadFolder($field).$value);

$files_move[] = $file_move;

return $value;
if($file["size"]>20481024)

return false;
$ext = substr($file["name"], strlen($file["name"])-4);

$ext=strtoupper($ext);

if($ext!=".TIF")

return false;
In the Before Record is added
if ($ext != ".TIF")

{$error = 1;

echo "Invalid file type, must be
.tif";}
error message is
Undefined variable: ext
Thanks

J
Jane 7/19/2007

Hi,
please make sure that you apply me changes carefully. It seems that you've moved added code in the generated include/commonfunction.php file and added your own code to the BeforeAdd event.

R
Rigmantas 3/6/2008

Hi,

Maybe I'm late but I want show my job <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=26724&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />

Before record added or Before record updated event on the Events tab put :
)-4);

$ext=strtoupper($ext);

if($ext!=".JPG" && $ext!="JPEG" && $ext!=".BMP")

{

echo "file must be jpg or bmp";

return false;

}

else

{

return true;

}

I don,t any change in include\commonfunctions.php.

I'm not sure for this true, but this work for me.

Thanks

Rimantas