Jump to content

Storing Filename for Images


phpbeginner

Recommended Posts

Good Day,

 

Was wondering if someone could help me out with this. I have a basic script which allows a user to upload and image. This stores the filename in SQL and then I have a code linking to the image which works fine. I had a request for 2 images per record and have been having some difficulty. Is there an easy way to do this with this code.

 

if (is_uploaded_file ($flFile))

        {
            move_uploaded_file($flFile,$dir.$flFile_name) ;

 

Basically, is there an easy way to do this ? Can I do something like

 

 

if (is_uploaded_file ($flFile))

        {
            move_uploaded_file($flFile,$dir.$flFile_name) ;


if (is_uploaded_file ($flFile2))

        {
            move_uploaded_file($flFile2,$dir.$flFile_name2) ;

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/
Share on other sites

Thanks for the response frost 110. Here is the deal now........ on my committ page I have added this code

 

foreach ($_FILES as $flFile) {
    move_uploaded_file($flFile['tmp_name'],$dir.$flFile['name']) ;

 

Now for uploading images I just have the name of the files as name="flFile". If I upload an image in Photo 1 nothing happens and it erases whatever I had in image 1 and image 2 fields, if i upload 2 images at once the second one appears for both images and if I just upload image 2 this also appears in both fields.

 

Again, in my upload script I have the name as "flFile" and then I have the input so it will insert that value into the correct row ( value=$row****[3], the other is  value=$row****[4] ).

 

I appreciate the help !

Here is the code I use upon submitting the images from my form.....Let me know if this helps. Thanks in Advance !

 

if($saveDel=='delete')
   {
       $rsFileName=mysql_query("select uploadedfile from tbl******* where id=" . $num*******);
   
       if(mysql_num_rows($rsFileName)!=0)
       {
           $rowFileName=mysql_fetch_row($rsFileName);
           if(chdir("././"))
           {
                $dir=opendir(".");
                unlink($rowFileName[0]);
                closedir($dir);
           }
       }

       $result=mysql_query("delete from tbl******* where id=" . $num*******);
   }
   elseif($saveDel=='edit')
   {


        $dir="././";

               if (!is_uploaded_file ($flFile)){

        $result=mysql_query("update tbl******* set title='" . $txtTitle . "', paragraph='" . $taIntro . "',price='" . $txtPrice . "' where id=" . $num*******);
        }

         
	foreach ($_FILES as $flFile) {
    move_uploaded_file($flFile,$dir.$flFile_name) ;

            
            $result=mysql_query("update tbl******* set title='" . $txtTitle . "', paragraph='" . $taIntro . "', uploadedfile='" . $flFile_name . "' , price='" . $txtPrice . "', uploadedfile2='" . $flFile_name . "' where id=" . $num*******);
        }

   }
   else
   {

       $result=mysql_query("insert into tbl*******(title,paragraph,uploadedfile,price,uploadedfile2) values('" . $txtTitle . "','" . $taIntro . "','" . $flFile_name . "','" . $txtPrice . "','" . $flFile_name . "')");

           $dir="././";

               if (!is_uploaded_file ($flFile))
  
      {
          
      }

      foreach ($_FILES as $flFile) {
    move_uploaded_file($flFile,$dir.$flFile_name) ;
      }
}

Can anyone help me with this. I have been banging my head over this for 2 days and still get the error above.

 

Here is the part of my submit form for the file upload....

<tr>
                                <td valign='top'>
                                    Upload Image: 
                                </td>
                                <td>
                                    <input type='file' value='<?php echo($row*****[3]); ?>' name='flFile'><?php echo($row*****[3]); ?>
                                </td>
                            </tr>  	 
						<tr>
                                <td valign='top'>
                                    Upload Image 2 ( if required ): 
                                </td>
                                <td>
                                    <input type='file' value='<?php echo($row*****[5]); ?>' name='flFile'><?php echo($row******[5]); ?>
                                </td>
                            </tr>

 

and here is the code upon submitting the form....

if($saveDel=='delete')
   {
       $rsFileName=mysql_query("select uploadedfile from tbl******* where id=" . $num*******);
   
       if(mysql_num_rows($rsFileName)!=0)
       {
           $rowFileName=mysql_fetch_row($rsFileName);
           if(chdir("././"))
           {
                $dir=opendir(".");
                unlink($rowFileName[0]);
                closedir($dir);
           }
       }

       $result=mysql_query("delete from tbl******* where id=" . $num*******);
   }
   elseif($saveDel=='edit')
   {


        $dir="././";

               if (!is_uploaded_file ($flFile)){

        $result=mysql_query("update tbl******* set title='" . $txtTitle . "', paragraph='" . $taIntro . "',price='" . $txtPrice . "' where id=" . $num*******);
        }

         
	foreach ($_FILES as $flFile) {
    move_uploaded_file($flFile['tmp_name'],$dir.$flFile['name'])  ;

            
            $result=mysql_query("update tbl******* set title='" . $txtTitle . "', paragraph='" . $taIntro . "', uploadedfile='" . $flFile_name . "' , price='" . $txtPrice . "', uploadedfile2='" . $flFile_name . "' where id=" . $num*******);
        }

   }
   else
   {

       $result=mysql_query("insert into tbl*******(title,paragraph,uploadedfile,price,uploadedfile2) values('" . $txtTitle . "','" . $taIntro . "','" . $flFile_name . "','" . $txtPrice . "','" . $flFile_name . "')");

           $dir="././";

               if (!is_uploaded_file ($flFile))
  
      {
          
      }

      foreach ($_FILES as $flFile) {
    move_uploaded_file($flFile['tmp_name'],$dir.$flFile['name']) ;
      }
}

 

Any help would be so much appreciated !

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.