nade93 Posted December 16, 2009 Share Posted December 16, 2009 Hi All I wanted to start a more specific thread for this probelm as it seemed to have got lost in my previous one. Basically, I have 5 Image file fields and at present all upload files and paths to a directory and to fields in my database. However, I am wanting to write a bit of coding that will allow me to place a standard image into the data base field if the form field is left empty below is the code as its stands at the moment. $image1 = ''.$_FILES["image1"]["name"]; move_uploaded_file($_FILES["image1"]["tmp_name"] , "$folder".$_FILES["image1"]["name"]); $image2 = ''.$_FILES["image2"]["name"]; move_uploaded_file($_FILES["image21"]["tmp_name"] , "$folder".$_FILES["image21"]["name"]); $image3 = ''.$_FILES["image3"]["name"]; move_uploaded_file($_FILES["image3"]["tmp_name"] , "$folder".$_FILES["image3"]["name"]); $image4 = ''.$_FILES["image4"]["name"]; move_uploaded_file($_FILES["image4"]["tmp_name"] , "$folder".$_FILES["image4"]["name"]); $image5 = ''.$_FILES["image5"]["name"]; move_uploaded_file($_FILES["image5"]["tmp_name"] , "$folder".$_FILES["image5"]["name"]); $image6 = ''.$_FILES["image6"]["name"]; move_uploaded_file($_FILES["image6"]["tmp_name"] , "$folder".$_FILES["image6"]["name"]); Any ideas please? Link to comment https://forums.phpfreaks.com/topic/185382-if-var-empty-insert-text/ Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 a.) There is really no point in putting the single quotes before $_FILES['image1']['name'], they add no meaning. b.) Similar to above, there is no point putting double quotes around a variable if no other text is used, just put $folder. c.) Would it not make more sense to leave the database empty, upon loading if the database is empty use a default image, this would make it much easier to change the default image and would take up less storage space. d.) You could do it like this... if(isset($_FILES['image1'])) { $image1 = $_FILES["image1"]["name"]; move_uploaded_file($_FILES["image1"]["tmp_name"] , $folder.$_FILES["image1"]["name"]); } else { $image1 = 'whatever your default is'; } Link to comment https://forums.phpfreaks.com/topic/185382-if-var-empty-insert-text/#findComment-978677 Share on other sites More sharing options...
nade93 Posted December 16, 2009 Author Share Posted December 16, 2009 thanks your a star!!!! Link to comment https://forums.phpfreaks.com/topic/185382-if-var-empty-insert-text/#findComment-978686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.