CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Image Upload to folder

Print topic Send  topic

Author Message
RipCurl
Posted: 02/14/2003, 4:13 PM


Hi,

I looked at the several articles about upload, and the one in PHP I found was great, but it uses "user" permission based in order to view or edit or upload.

all i need is a simple upload script in PHP with templates when I am adding or editing a record.

Images will go into a folder called titleimages
the DB table that it needs to be added to is called title that has information about a particular movie or book. the table contains these fields: title_id, titlename, titlesummary, titleyear, titlepublisher, titlegenre, titleimage.

right now all I have in the titleimage per records is just as <img src="directory/file"> and the record form just parses it out as HTML (label).

How can i change it so it doesn't need to us <img src"> and just use directory/file?

Only admin will have rights to edit and upload.
Ken
Posted: 02/16/2003, 9:43 PM

I wrote an external PHP script that will do this for you. You call it from within CCS and it will update the MySQL DB with the corect link to the uploaded file. The example code can be found here:

http://www.kabwebs.com/ccsniplets/index.php
RipCurl
Posted: 02/17/2003, 10:05 AM

Hi, thanks, but i need this for Code Charge not studio.
Catchup
Posted: 02/17/2003, 1:24 PM

I have a similar need for uploading images to a folder...
First of all this is the first post here and I should say that I've never done the PHP and MySQL thing in the past because, frankly, it scared the hell out of me.

Anyway, back to what I'm trying to accomplish...
I have placed a slide show script within the DB and have modified it so the one script is called for all of the records in the DB that show a specific product, this part works just slick as all get out...

I've setup the site so the owner can edit the Inventory and change the items listing and details records very easily. The only thing left is to allow the owner of the site to upload images to individual item image folders. The Images tree is simply ./InventImages/{img_directory}/image.xxx. All the images in all of the image folders are named alike IE: thumb.jpg; slide_1.jpg; slide_2.jpg; etc up to slide_6.jpg

What I'm seeing in the example codes is the use of a UserID parameter to set the folder and upload files to the folder... This isn't going to work because I have like 200 item image folders that are identified with a number from 0 to 200 so, what I need to have is something that the uploader can build a string with that uses the item_id and will place the img_directory folder as the folder to upload to... Understand?

Like:

$db->query("Select imgs_directory from items where item_id=" $flditem_id ");
$db->next_record();
$ImgFolder=$db->f("imgs_directory");

$d=dir($p."/InventImages/" );
$ex=false;
while($entry=$d->read())
{
if($entry == $ImgFolder)
$ex=true;
}
$d->close();
if(!$ex)
{
mkdir($p."/InventImages/" .$ImgFolder,0777);
}
if( get_param("action") == "delete" )
{
unlink($p."/InventImages/".$ImgFolder."/". get_param("filename"));
header("Location: ItemMaint.php");

This code doesn't seem to work, obviously or I wouldn't be here. I always get a Parse error... Any help with this would be extremely helpful...

I got the thing to work in another area that does use the UserID session and it works fine, but I can't see loging in with a different username for every folder that has item images in them...

Catchup
PS: After aquiring CodeCharge and working with it for a while I find the PHP and MySQL is the greatest thing since sliced bread!
Thanks for turning me around...
feha
Posted: 02/23/2003, 1:43 AM

You forgot to add at the end } (to close your IF statment ...

$db->query("Select imgs_directory from items where item_id=" $flditem_id ");
$db->next_record();
$ImgFolder=$db->f("imgs_directory");

$d=dir($p."/InventImages/" );
$ex=false;
while($entry=$d->read())
{
if($entry == $ImgFolder)
$ex=true;
}
$d->close();
if(!$ex)
{
mkdir($p."/InventImages/" .$ImgFolder,0777);
}
if( get_param("action") == "delete" )
{
unlink($p."/InventImages/".$ImgFolder."/". get_param("filename"));
header("Location: ItemMaint.php");
}


That should be a reason for parse erorr ...


regards
feha
[www.vision.to]


Catchup
Posted: 02/23/2003, 3:35 PM

Well, after much frustration and the obvious lack of ability to comprehend the language of PHP, (all though i am learning) I have done at least part of what I've set out to do. I can upload images (multiple) and not use the User session script but,,, I can only get the thing to work if I manually insert the value for $imgs_directory.

Here's where my problem lies:
$db->query("Select imgs_directory from items where imgs_directory=$fldimgs_directory ");

This is the first line in the "BeforeShow" event that produces the "FilesList".
If I run the app as is, I get a MySQL error:

Invalid SQL: Select imgs_directory from items where imgs_directory=
MySQL Error: 1064 (You have an error in your SQL syntax near '' at line 1)

Now if I insert a value for $fld_imgs_directory, this is a number, IE:19 the script works just fine, images are uploaded to the #19 folder and listed on the Upload.php page with the folder path set correctly IE: /test/slides/19/

What I can't seem to get through my head is just how to dynamically insert the proper value for $fldimgs_directory. I have tried setting it every which way I can think of. The value for $fldimgs_directory should be transmitted from the page with the image selection, browse buttons and upload button but, I need a little help with the proper way to write the string so it works right.

This is the entire "BeforeShow" event that makes the "FilesList" on the Upload.php page. I can get everything to work right except that first line and it will work if I manually insert the value as a number.

$db->query("Select imgs_directory from items where imgs_directory= . $fldimgs_directory ");
$db->next_record();
$ImgFold=$db->f("imgs_directory");
global $PATH_TRANSLATED;
$pt = str_replace("\","/",$PATH_TRANSLATED);
$p = substr($pt,0,strrpos($pt,"/"));

$handle=opendir($p."/slides/" .$ImgFold);
global $REQUEST_URI;
$s="<font size=1 face=Arial>Folder: " . substr($REQUEST_URI,0,strrpos($REQUEST_URI,"/")). "/slides/" . $ImgFold . "</font><br><B>";

while (false!==($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$s = $s . "<a href=slides/" . $ImgFold ."/" .$file. ">" .$file. "</a>  <a href=Uploader.php?action=delete&filename=" .$file. ">Delete</a>";
$s = $s . "<BR>";
}
}
closedir($handle);

$tpl->set_var("FilesList", $s . "</B>");

Here is the script that makes the "Results" form work. Both forms are on the same Upload.php page and they both work IF I enter a value for $fldimgs_directory, manually.

check_security(1);

global $PATH_TRANSLATED;
$pt = str_replace("\","/",$PATH_TRANSLATED);
$p = substr($pt,0,strrpos($pt,"/"));

$db->query("Select imgs_directory from items where imgs_directory= .$fldimgs_directory ");
$db->next_record();
$ImgFold=$db->f("imgs_directory");

$d=dir($p."/slides/" );
$ex=false;
while($entry=$d->read())
{
if($entry == $ImgFold)
$ex=true;
}
$d->close();
if(!$ex)
{
mkdir($p."/slides/" .$ImgFold,0777);
}
if( get_param("action") == "delete" )
{
unlink($p."/slides/".$ImgFold."/". get_param("filename"));
header("Location: AdminInventory.php");
}

$MaxFileSize=20000;
$MaxFileCount =15;
$upload_err="";
for($i=1;$i<=$MaxFileCount;$i++)
{
$f = "my_image".$i;
$f_name = "my_image".$i."_name";
$f_size = "my_image".$i."_size";

global $$f;
global $$f_name;
global $$f_size;
if( file_exists($$f))
{
if($$f_size <=$MaxFileSize)
{
copy($$f,$p."/slides/".$ImgFold."/".$$f_name);
}
else
{
$upload_err=$upload_err.$$f_name." is big<br>";
}
}
}

if($upload_err !="")
$ResultString="Sorry, following error occured:".$upload_err;
else
$ResultString="Success! Your files were uploaded";

====================
Sorry this is taking up so much room...

PS: I've used the bookstore app to make a details page that includes a slide show script using php and MySQL if anyone wants to take a peek at it...

I'm still working on the checkout thing and it isn't quite finished yet but the slide show is pretty neat...

http://tincreations.com/cc/Default.php

Let me know what you think...

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.