PHP inserting image and video into one mysql record -
PHP inserting image and video into one mysql record -
i able insert image , video file mysql database, creating 2 records. belief because of "type" field, it's not able create 2 different values same record, created "type" , "type2" thinking solve issue. created same "image/png" value. here form script:
<form action="saveimage.php" enctype="multipart/form-data" method="post"> <table style="border-collapse: collapse; font: 12px tahoma;" border="1" cellspacing="5" cellpadding="5"> <tbody> <tr><td>picture:</td><td><input name="rpic" type="file" accept="image/*"></td></tr> <tr><td>video:</td><td><input name="rvideo" type="file" accept="video/*"></td></tr> <tr><td><input name="upload now" type="submit" value="upload"></td></tr> </tbody></table> </form>
this script inserting files:
<?php include("config.php"); error_reporting(e_error | e_parse); function getimageextension($rpic) { if(empty($rpic)) homecoming false; switch($rpic) { case 'image/bmp': homecoming '.bmp'; case 'image/gif': homecoming '.gif'; case 'image/jpeg': homecoming '.jpg'; case 'image/png': homecoming '.png'; default: homecoming false; } } function getvideoextension($rvideo) { if(empty($rvideo)) homecoming false; switch($rvideo) { case 'video/asf': homecoming '.asf'; case 'video/avi': homecoming '.avi'; case 'video/wmv': homecoming '.wmv'; default: homecoming false; } } if (!empty($_files["rpic"]["name"])) { $file_name=$_files["rpic"]["name"]; $temp_name=$_files["rpic"]["tmp_name"]; $type=$_files["rpic"]["type"]; $ext= getimageextension($type); $name=$_files["rpic"]["name"]; $path = "uploads/".$name; if(move_uploaded_file($temp_name, $path)) { $query_upload="insert recipes (type, rpic, path, posted) values ('".$type."','".$rpic."','".$path."','".date("y-m-d")."')"; mysql_query($query_upload) or die("error in $query_upload == ----->".mysql_error()); } else { exit("error while uploading file."); } } if (!empty($_files["rvideo"]["name"])) { $file_name=$_files["rvideo"]["name"]; $temp_name=$_files["rvideo"]["tmp_name"]; $type=$_files["rvideo"]["type"]; $ext= getvideoextension($type2); $name=$_files["rvideo"]["name"]; $path = "uploads/".$name; $pathvideo = "uploads/".$name; if(move_uploaded_file($temp_name, $pathvideo)) { $query_upload="insert recipes (type, rvideo, pathvideo, posted) values ('".$type."','".$rvideo."','".$pathvideo."','".date("y-m-d")."')"; mysql_query($query_upload) or die("error in $query_upload == ----->".mysql_error()); } else { exit("error while uploading file."); } } ?>
any help provide appreciated. again, prefer have 1 record created. in advance!
here inserting both photo & video @ same-time, in meantime need both validation & db insertion. so,use flag concept attain this,
// flag declaration $flag_photo=0; $flag_video=0;
if (!empty($_files["rpic"]["name"])) { $file_name=$_files["rpic"]["name"]; $temp_name=$_files["rpic"]["tmp_name"]; $type=$_files["rpic"]["type"]; $ext= getimageextension($type); $name=$_files["rpic"]["name"]; $path = "uploads/".$name; if(move_uploaded_file($temp_name, $path)) { $flag_photo=1; } else { $flag_photo=0; //exit("error while uploading file."); } } if (!empty($_files["rvideo"]["name"])) { $file_name=$_files["rvideo"]["name"]; $temp_name=$_files["rvideo"]["tmp_name"]; $type=$_files["rvideo"]["type"]; $ext= getvideoextension($type2); $name=$_files["rvideo"]["name"]; $path = "uploads/".$name; $pathvideo = "uploads/".$name; if(move_uploaded_file($temp_name, $pathvideo)) { $flag_video=1; } else { $flag_video=0; } } if($flag_photo ==1 && $flag_video==1) { $query_upload="insert recipes (type, rpic, path, rvideo, pathvideo, posted) values
('".$type."','".$rpic."','".$path."','".$rvideo."','".$pathvideo."','".date("y-m-d")."')"; mysql_query($query_upload) or die("error in $query_upload == ----->".mysql_error()); } else { exit("error while uploading file."); }
php mysql
Comments
Post a Comment