phpbeginner Posted March 27, 2007 Share Posted March 27, 2007 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) ; Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/ Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 If the structure is right, but why not use a foreach loop? foreach ($_FILES as $file) { move_uploaded_file($file['tmp_name'],$dir.$file['name']) ; } I am not sure of the move_upload_file parameters, but yea thats the basic idea. Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216088 Share on other sites More sharing options...
phpbeginner Posted March 27, 2007 Author Share Posted March 27, 2007 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216104 Share on other sites More sharing options...
phpbeginner Posted March 27, 2007 Author Share Posted March 27, 2007 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) ; } } Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216139 Share on other sites More sharing options...
phpbeginner Posted March 27, 2007 Author Share Posted March 27, 2007 Help Me Frost110 ! LOL . Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216393 Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 move_uploaded_file($flFile,$dir.$flFile_name) ; should be move_uploaded_file($flFile['tmp_name'],$dir.$flFile['name']) ; Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216398 Share on other sites More sharing options...
phpbeginner Posted March 27, 2007 Author Share Posted March 27, 2007 Same thing happens. Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216407 Share on other sites More sharing options...
phpbeginner Posted March 27, 2007 Author Share Posted March 27, 2007 I still get these errors. When I upload image 1 it uploads nothing. If I upload image 2 it goes into both image 1 and image 2 field. If I then go back and try image 1 it erases both. Any ideas ? Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216431 Share on other sites More sharing options...
phpbeginner Posted March 28, 2007 Author Share Posted March 28, 2007 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216700 Share on other sites More sharing options...
Greaser9780 Posted March 28, 2007 Share Posted March 28, 2007 When you are uploading the files from your form you need to give each its own name so: <input type="file" name="flfile"> <input type="file" name="flfile2"> Make sense. Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216713 Share on other sites More sharing options...
phpbeginner Posted March 28, 2007 Author Share Posted March 28, 2007 Thanks for the response Greaser. I did try that before I posted but it did the same thing..... I think I even tried <input type="file" name="flfile[]"> <input type="file" name="flfile[2]"> Quote Link to comment https://forums.phpfreaks.com/topic/44488-storing-filename-for-images/#findComment-216719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.