cdmafra Posted March 18, 2014 Share Posted March 18, 2014 Hello. I am trying to upload photos with PHP and MYSQL for my website. How must I to do that? I'm trying, I have the required <input>, but when I publish it returns me: " Notice: Undefined index: news_image in C:\wamp\www\mrn_site\login\main.php on line 75", and the picture don't goes to required directory if (isset($_POST["publish-p"])) { $news_image= mysql_real_escape_string($_POST['news_image']); } { if (($_FILES['news_image'])) { move_uploaded_file($_FILES['news_image']['tmp_name'], "../images".$_FILES['news_image']); } Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/ Share on other sites More sharing options...
Psycho Posted March 18, 2014 Share Posted March 18, 2014 That is nowhere near how the process works for file uploads. Here is a good tutorial you can review: http://www.tizag.com/phpT/fileupload.php Go read that, then write your code. If you have problems then post back. Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473055 Share on other sites More sharing options...
requinix Posted March 18, 2014 Share Posted March 18, 2014 How about posting the rest of your code? And the HTML form too. Speaking of the form, does it have an enctype="multipart/form-data"? Take a look here if you haven't see that yet. Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473056 Share on other sites More sharing options...
cdmafra Posted March 18, 2014 Author Share Posted March 18, 2014 (edited) If I understood, the uploader.php file it's only that: <?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "O ficheiro ". basename( $_FILES['uploadedfile']['name']). " foi carregado"; } else{ echo "Ocorreu um erro, tente novamente!"; } ?> And the Html line I need to enter is <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> However, it nothing is happening... even after all details setted-up as tutorial Edited March 18, 2014 by cdmafra Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473058 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 However, it nothing is happening... even after all details setted-up as tutorial Are you running into a white page or you're getting a message that the upload is not successful? You should consider turning on php error reporting which will give you(us) some indication of where or what the problem is. Put the following code on the top of the uploader.php file. ini_set('display_errors',1); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473074 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 Are you running into a white page or you're getting a message that the upload is not successful? You should consider turning on php error reporting which will give you(us) some indication of where or what the problem is. Put the following code on the top of the uploader.php file. ini_set('display_errors',1); error_reporting(E_ALL); It just seems that there is no redirect to the uploader.php, I order to upload the file, but only refreshes the page Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473080 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 It just seems that there is no redirect to the uploader.php, I order to upload the file, but only refreshes the page Then, post out the entire script of the uploader.php file and the content of this file containing the html uploading form. Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473101 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 Then, post out the entire script of the uploader.php file and the content of this file containing the html uploading form. I just followed exactly the steps in this link http://www.tizag.com/phpT/fileupload.php Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473103 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 Did you put error_reporting functions at the top of the uploader.php file? Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473110 Share on other sites More sharing options...
Psycho Posted March 19, 2014 Share Posted March 19, 2014 I just followed exactly the steps in this link http://www.tizag.com/phpT/fileupload.php If you want help, please provide the information requested. Jazzman requested that you post the code for the form page and the uploader page and you just linked to the tutorial. How do we know that there isn't a typo or that something else isn't quite right in your code. We can't help fix something if you aren't going to share it with us. Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473130 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 UPLOAD form page: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta lang="en_US" /> <meta name="viewport" content="width=device-width" /><!-- Set the viewport width to device width for mobile --> <title>Publicar notícia MRN</title> <link href="../stylesheets/foundation.min.css" rel="stylesheet" type="text/css" /> <link href="../stylesheets/app.css" rel="stylesheet" type="text/css" /> <link href="../stylesheets/admin.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <link rel="shortcut icon" href="../images/logobar.ico" type="image/x-icon"> <script src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript" src="../js/jquery.formvalidator.js?upd=1.5.1"></script> <script type="text/javascript" src="tinymce/tinymce.min.js"></script> </head> <body > <div class="bo-header"><div class="row"><div class="twelve columns"> <p>Olá <?php echo "<strong>".$_SESSION["name"]."</strong>."; ?><br/><strong><a href="?logout">Logout</a></strong></p> </div></div></div> <!--MENU--> <!-- Navigation --> <nav class="top-bar fixed"> <div class="twelve columns" ><div style="background:url(../images/carbonback.png); margin-top:2px;"><img src="../images/cabecresize.png" alt="Cabeçalho"></div></div> <ul> <li class="name"><h1 class="menu_dp">Menu</h1></li> <li class="toggle-topbar"><a href="#"></a></li> </ul> <section> <ul class="left"> <!--<li class="menu"><a href="?perfil" title="Ver perfil">Perfil</a></li>--> <li class="menu"><a href="?submit-news" title="Publicar notícia MRN">Publicar notícia MRN</a></li> </ul> </section></nav> <hr class="linha"/> <?php if (get_magic_quotes_gpc()) { function stripslashes_gpc(&$value) { $value = stripslashes($value); } array_walk_recursive($_GET, 'stripslashes_gpc'); array_walk_recursive($_POST, 'stripslashes_gpc'); array_walk_recursive($_COOKIE, 'stripslashes_gpc'); array_walk_recursive($_REQUEST, 'stripslashes_gpc'); } ?> <?php if (isset($_POST["publish-p"])) { $categoria= mysql_real_escape_string($_POST['categoria']); $categoria2= mysql_real_escape_string($_POST['categoria2']); $destaque= mysql_real_escape_string($_POST['destaque']); $publicado= mysql_real_escape_string($_POST['publicado']); $news_title= mysql_real_escape_string($_POST['news_title']); $news_subtitle= mysql_real_escape_string($_POST['news_subtitle']); $news_desc= mysql_real_escape_string($_POST['news_desc']); $news_post= mysql_real_escape_string($_POST['news_post']); $news_date= mysql_real_escape_string($_POST['news_date']); $hour= mysql_real_escape_string($_POST['hour']); $news_image= mysql_real_escape_string($_POST['news_image']); $news_image_peq= mysql_real_escape_string($_POST['news_image_peq']); $copyright= mysql_real_escape_string($_POST['copyright']); $publish="INSERT INTO news(news_guid,categoria,categoria2,destaque,publicado,news_title,news_subtitle,news_desc,news_post,news_date,hour,news_image,news_image_peq,copyright) VALUES(uuid(),'$categoria','$categoria2','$destaque','$publicado','$news_title','$news_subtitle','$news_desc','$news_post','$news_date','$hour','$news_image','$news_image_peq','$copyright')"; mysql_query($publish) OR DIE(mysql_error()); //mensagem após submeter dados echo "<script>alert('Notícia publicada!');</script>"; } ?> <!--CONTEUDO--> <div class="row"> <div class="twelve columns"> <form action="#" method="post" onsubmit="return $(this).validate()" name="publish" > <h3 class="n3">Publicar notícia</h3> <div class="publish-content"> <div> <h3 class="n3v4">Categoria</h3> <select name="categoria"> <option value="Autos/Pistas">Autos/Pistas</option> <option value="Autos/Ralis-TT">Autos/Ralis-TT</option> <option value="Motos/Pistas">Motos/Pistas</option> <option value="Motos/Ralis-TT">Motos/Ralis-TT</option> <option value="Outros">Outros</option> <option value="Entrevistas">Entrevistas</option> <option value="ci">C&I: OnTheRoad</option> <option value="Multimedia">Multimédia</option> </select> </div> <br/> <div> <h3 class="n3v4">Categoria 2 (opcional)</h3> <select name="categoria2"> <option value="">Nenhuma</option> <option value="Autos/Pistas">Autos/Pistas</option> <option value="Autos/Ralis-TT">Autos/Ralis-TT</option> <option value="Motos/Pistas">Motos/Pistas</option> <option value="Motos/Ralis-TT">Motos/Ralis-TT</option> <option value="Outros">Outros</option> <option value="Entrevistas">Entrevistas</option> <option value="ci">C&I: OnTheRoad</option> <option value="Multimedia">Multimédia</option> </select> </div> <br/> <h3 class="n3v4">Destaque?</h3> <label class="cbox"> <input type="radio" name="destaque" value="sim" checked>Sim</input> <input type="radio" name="destaque" value="não">Não</input> </label> <br/> <h3 class="n3v4">Publicar já?</h3> <label class="cbox"> <input type="radio" name="publicado" value="sim" checked>Sim</input> <input type="radio" name="publicado" value="não">Não</input> </label> <br/> <input name="news_title" type="text" class="title" placeholder="(título)" data-validation="required" title="required"/> <input name="news_subtitle" type="text" class="title" placeholder="(subtítulo)" data-validation="required" /> <input name="news_desc" type="text" class="description" placeholder="(descrição)" data-validation="required" title="required" maxlength="165"/> <textarea name="news_post" type="text" class="post" placeholder="(notícia)" data-validation="required" title="required" ></textarea> <input name="news_date" type="text" class="date" placeholder="(data)" data-validation="required" title="required" id="datepicker" /> <input name="hour" type="text" class="description" placeholder="(hora HH:MM)" data-validation="required" title="required" maxlength="5" data-format="hh:mm:ss" id="datetimepicker3" /> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <input name="news_image" type="text" class="description" placeholder="(imagem homepage)" data-validation="required" title="required"/> <input name="news_image" type="text" class="description" placeholder="(imagem main)" data-validation="required" title="required"/> <input name="news_image_peq" type="text" class="description" placeholder="(imagem pequena)" data-validation="required" title="required"/> <input name="copyright" type="text" class="description" placeholder="(Copyright da/s Imagem/ns)" data-validation="required" title="required"/></div> <div class="publish-footer"> <input type="submit" name="publish-p" value="Publicar" class="button"> <input type="submit" name="cancel" value="Cancelar" class="secondary button" onclick="window.location='../login/?submit-news'" > </div> </form> </div> </div> <?php include ("rodape.php") ?> <!--SCRIPTS--> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(function() { $( "#datepicker" ).datepicker({ changeYear: true, dateFormat: "dd'-'mm'-'yy", showButtonPanel: true, }); }); </script> <!-- script para Toogle Menu --> <script src="../js/toogle-menu.js"></script> <script type="text/javascript"> tinymce.init({ selector: "textarea", plugins: [ "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker", "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", "save table contextmenu directionality emoticons template textcolor colorpicker", "paste" ], image_advtab: true, font_size_style_values: "9px,10px,11px,12px,13px,14px,16px,18px,20px", toolbar1: "sizeselect | bold italic | insertfile undo redo | styleselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media",//used font size for showing font size toolbar toolbar2: "fontselect | fontsizeselect | colorpicker",//used font size for showing font size toolbar style_formats: [ {title: 'Bold text', inline: 'b'}, {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}}, {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}}, {title: 'Example 1', inline: 'span', classes: 'example1'}, {title: 'Example 2', inline: 'span', classes: 'example2'}, {title: 'Table styles'}, {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'} ], resize: false, inline_styles : true, }); </script> </body> </html> Uploader.php: <?php ini_set('display_errors',1); error_reporting(E_ALL);?> <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473136 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 You can have several forms in html document but they shouldn't be nested like in the example above. Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473142 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 You can have several forms in html document but they shouldn't be nested like in the example above. So, I need to separate them to the image uploader works properly? Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473145 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 (edited) Yes, you need to separate them or just to redesign your current script using only one form tag. Edited March 19, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473146 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 Yes, you need to separate them or just to redesign your current script using only one form tag. Right. And can I do that without a uploader.php page, I mean, all integrated in the same, with no redirects? Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473149 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 Yes, you can, everything depends on your wishes. Google "ajax" Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473151 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 (edited) Yes, you can, everything depends on your wishes. Google "ajax" Right, now it works, the picture is uploaded, but it goes to uploader.php page and "deletes" the rest of article by not posting that. And I need to upload also for mysql DB Edited March 19, 2014 by cdmafra Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473153 Share on other sites More sharing options...
jazzman1 Posted March 19, 2014 Share Posted March 19, 2014 (edited) You need to find some decent tutorial on the web how to upload a binary file to the file server using php/mysql/ajax. Edited March 19, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473155 Share on other sites More sharing options...
Psycho Posted March 19, 2014 Share Posted March 19, 2014 Slow down, you are making changes without having any understanding of what you are doing. You want to have ONE form with the normal form data AND the file input filed for the upload. Then have the form post to ONE page to do the processing. Go ahead and have the form post back to itself as you were previously. Then, after you have processed the text input and added to the database, add additional code to implement the saving of the file upload. Actually, you should be splitting out the functionality into separate functions or PHP pages to help keep things tidy. But, for now, go ahead and implement it all in one page. Just use comments and structure within your code to keep it organized. Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473161 Share on other sites More sharing options...
Psycho Posted March 19, 2014 Share Posted March 19, 2014 I'm not making any promises, but you can give this a try <?php if (get_magic_quotes_gpc()) { function stripslashes_gpc(&$value) { $value = stripslashes($value); } array_walk_recursive($_GET, 'stripslashes_gpc'); array_walk_recursive($_POST, 'stripslashes_gpc'); array_walk_recursive($_COOKIE, 'stripslashes_gpc'); array_walk_recursive($_REQUEST, 'stripslashes_gpc'); } $message = ''; if (isset($_POST["publish-p"])) { $categoria= mysql_real_escape_string($_POST['categoria']); $categoria2= mysql_real_escape_string($_POST['categoria2']); $destaque= mysql_real_escape_string($_POST['destaque']); $publicado= mysql_real_escape_string($_POST['publicado']); $news_title= mysql_real_escape_string($_POST['news_title']); $news_subtitle= mysql_real_escape_string($_POST['news_subtitle']); $news_desc= mysql_real_escape_string($_POST['news_desc']); $news_post= mysql_real_escape_string($_POST['news_post']); $news_date= mysql_real_escape_string($_POST['news_date']); $hour= mysql_real_escape_string($_POST['hour']); $news_image= mysql_real_escape_string($_POST['news_image']); $news_image_peq= mysql_real_escape_string($_POST['news_image_peq']); $copyright= mysql_real_escape_string($_POST['copyright']); $publish="INSERT INTO news (news_guid, categoria, categoria2, destaque, publicado, news_title, news_subtitle, news_desc, news_post, news_date, hour, news_image, news_image_peq, copyright) VALUES (uuid(), '$categoria', '$categoria2', '$destaque', '$publicado', '$news_title', '$news_subtitle', '$news_desc', '$news_post', '$news_date', '$hour', '$news_image', '$news_image_peq', '$copyright')"; mysql_query($publish) OR DIE(mysql_error()); //mensagem após submeter dados $message = "<script>alert('Notícia publicada!');</script>"; //Add image upload if(isset($_FILES['uploadedfile'])) { $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $message .= "<br>The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ $message .= "<br>There was an error uploading the file, please try again!"; } } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta lang="en_US" /> <meta name="viewport" content="width=device-width" /><!-- Set the viewport width to device width for mobile --> <title>Publicar notícia MRN</title> <link href="../stylesheets/foundation.min.css" rel="stylesheet" type="text/css" /> <link href="../stylesheets/app.css" rel="stylesheet" type="text/css" /> <link href="../stylesheets/admin.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <link rel="shortcut icon" href="../images/logobar.ico" type="image/x-icon"> <script src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript" src="../js/jquery.formvalidator.js?upd=1.5.1"></script> <script type="text/javascript" src="tinymce/tinymce.min.js"></script> </head> <body> <div class="bo-header"><div class="row"><div class="twelve columns"> <p>Olá <?php echo "<strong>".$_SESSION["name"]."</strong>."; ?><br/><strong><a href="?logout">Logout</a></strong></p> </div></div></div> <!--MENU--> <!-- Navigation --> <nav class="top-bar fixed"> <div class="twelve columns" ><div style="background:url(../images/carbonback.png); margin-top:2px;"><img src="../images/cabecresize.png" alt="Cabeçalho"></div></div> <ul> <li class="name"><h1 class="menu_dp">Menu</h1></li> <li class="toggle-topbar"><a href="#"></a></li> </ul> <section> <ul class="left"> <!--<li class="menu"><a href="?perfil" title="Ver perfil">Perfil</a></li>--> <li class="menu"><a href="?submit-news" title="Publicar notícia MRN">Publicar notícia MRN</a></li> </ul> </section></nav> <hr class="linha"/> <?php echo $message; ?> <!--CONTEUDO--> <div class="row"> <div class="twelve columns"> <form action="#" method="post" onsubmit="return $(this).validate()" name="publish" > <h3 class="n3">Publicar notícia</h3> <div class="publish-content"> <div> <h3 class="n3v4">Categoria</h3> <select name="categoria"> <option value="Autos/Pistas">Autos/Pistas</option> <option value="Autos/Ralis-TT">Autos/Ralis-TT</option> <option value="Motos/Pistas">Motos/Pistas</option> <option value="Motos/Ralis-TT">Motos/Ralis-TT</option> <option value="Outros">Outros</option> <option value="Entrevistas">Entrevistas</option> <option value="ci">C&I: OnTheRoad</option> <option value="Multimedia">Multimédia</option> </select> </div> <br/> <div> <h3 class="n3v4">Categoria 2 (opcional)</h3> <select name="categoria2"> <option value="">Nenhuma</option> <option value="Autos/Pistas">Autos/Pistas</option> <option value="Autos/Ralis-TT">Autos/Ralis-TT</option> <option value="Motos/Pistas">Motos/Pistas</option> <option value="Motos/Ralis-TT">Motos/Ralis-TT</option> <option value="Outros">Outros</option> <option value="Entrevistas">Entrevistas</option> <option value="ci">C&I: OnTheRoad</option> <option value="Multimedia">Multimédia</option> </select> </div> <br/> <h3 class="n3v4">Destaque?</h3> <label class="cbox"> <input type="radio" name="destaque" value="sim" checked>Sim</input> <input type="radio" name="destaque" value="não">Não</input> </label> <br/> <h3 class="n3v4">Publicar já?</h3> <label class="cbox"> <input type="radio" name="publicado" value="sim" checked>Sim</input> <input type="radio" name="publicado" value="não">Não</input> </label> <br/> <input name="news_title" type="text" class="title" placeholder="(título)" data-validation="required" title="required"/> <input name="news_subtitle" type="text" class="title" placeholder="(subtítulo)" data-validation="required" /> <input name="news_desc" type="text" class="description" placeholder="(descrição)" data-validation="required" title="required" maxlength="165"/> <textarea name="news_post" type="text" class="post" placeholder="(notícia)" data-validation="required" title="required" ></textarea> <input name="news_date" type="text" class="date" placeholder="(data)" data-validation="required" title="required" id="datepicker" /> <input name="hour" type="text" class="description" placeholder="(hora HH:MM)" data-validation="required" title="required" maxlength="5" data-format="hh:mm:ss" id="datetimepicker3" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> <input name="news_image" type="text" class="description" placeholder="(imagem homepage)" data-validation="required" title="required"/> <input name="news_image" type="text" class="description" placeholder="(imagem main)" data-validation="required" title="required"/> <input name="news_image_peq" type="text" class="description" placeholder="(imagem pequena)" data-validation="required" title="required"/> <input name="copyright" type="text" class="description" placeholder="(Copyright da/s Imagem/ns)" data-validation="required" title="required"/></div> <div class="publish-footer"> <input type="submit" name="publish-p" value="Publicar" class="button"> <input type="submit" name="cancel" value="Cancelar" class="secondary button" onclick="window.location='../login/?submit-news'" > </div> </form> </div> </div> <?php include ("rodape.php") ?> <!--SCRIPTS--> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(function() { $( "#datepicker" ).datepicker({ changeYear: true, dateFormat: "dd'-'mm'-'yy", showButtonPanel: true, }); }); </script> <!-- script para Toogle Menu --> <script src="../js/toogle-menu.js"></script> <script type="text/javascript"> tinymce.init({ selector: "textarea", plugins: [ "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker", "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", "save table contextmenu directionality emoticons template textcolor colorpicker", "paste" ], image_advtab: true, font_size_style_values: "9px,10px,11px,12px,13px,14px,16px,18px,20px", toolbar1: "sizeselect | bold italic | insertfile undo redo | styleselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media",//used font size for showing font size toolbar toolbar2: "fontselect | fontsizeselect | colorpicker",//used font size for showing font size toolbar style_formats: [ {title: 'Bold text', inline: 'b'}, {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}}, {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}}, {title: 'Example 1', inline: 'span', classes: 'example1'}, {title: 'Example 2', inline: 'span', classes: 'example2'}, {title: 'Table styles'}, {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'} ], resize: false, inline_styles : true, }); </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473166 Share on other sites More sharing options...
cdmafra Posted March 19, 2014 Author Share Posted March 19, 2014 I'm not making any promises, but you can give this a try <?php if (get_magic_quotes_gpc()) { function stripslashes_gpc(&$value) { $value = stripslashes($value); } array_walk_recursive($_GET, 'stripslashes_gpc'); array_walk_recursive($_POST, 'stripslashes_gpc'); array_walk_recursive($_COOKIE, 'stripslashes_gpc'); array_walk_recursive($_REQUEST, 'stripslashes_gpc'); } $message = ''; if (isset($_POST["publish-p"])) { $categoria= mysql_real_escape_string($_POST['categoria']); $categoria2= mysql_real_escape_string($_POST['categoria2']); $destaque= mysql_real_escape_string($_POST['destaque']); $publicado= mysql_real_escape_string($_POST['publicado']); $news_title= mysql_real_escape_string($_POST['news_title']); $news_subtitle= mysql_real_escape_string($_POST['news_subtitle']); $news_desc= mysql_real_escape_string($_POST['news_desc']); $news_post= mysql_real_escape_string($_POST['news_post']); $news_date= mysql_real_escape_string($_POST['news_date']); $hour= mysql_real_escape_string($_POST['hour']); $news_image= mysql_real_escape_string($_POST['news_image']); $news_image_peq= mysql_real_escape_string($_POST['news_image_peq']); $copyright= mysql_real_escape_string($_POST['copyright']); $publish="INSERT INTO news (news_guid, categoria, categoria2, destaque, publicado, news_title, news_subtitle, news_desc, news_post, news_date, hour, news_image, news_image_peq, copyright) VALUES (uuid(), '$categoria', '$categoria2', '$destaque', '$publicado', '$news_title', '$news_subtitle', '$news_desc', '$news_post', '$news_date', '$hour', '$news_image', '$news_image_peq', '$copyright')"; mysql_query($publish) OR DIE(mysql_error()); //mensagem após submeter dados $message = "<script>alert('Notícia publicada!');</script>"; //Add image upload if(isset($_FILES['uploadedfile'])) { $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $message .= "<br>The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ $message .= "<br>There was an error uploading the file, please try again!"; } } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta lang="en_US" /> <meta name="viewport" content="width=device-width" /><!-- Set the viewport width to device width for mobile --> <title>Publicar notícia MRN</title> <link href="../stylesheets/foundation.min.css" rel="stylesheet" type="text/css" /> <link href="../stylesheets/app.css" rel="stylesheet" type="text/css" /> <link href="../stylesheets/admin.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <link rel="shortcut icon" href="../images/logobar.ico" type="image/x-icon"> <script src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript" src="../js/jquery.formvalidator.js?upd=1.5.1"></script> <script type="text/javascript" src="tinymce/tinymce.min.js"></script> </head> <body> <div class="bo-header"><div class="row"><div class="twelve columns"> <p>Olá <?php echo "<strong>".$_SESSION["name"]."</strong>."; ?><br/><strong><a href="?logout">Logout</a></strong></p> </div></div></div> <!--MENU--> <!-- Navigation --> <nav class="top-bar fixed"> <div class="twelve columns" ><div style="background:url(../images/carbonback.png); margin-top:2px;"><img src="../images/cabecresize.png" alt="Cabeçalho"></div></div> <ul> <li class="name"><h1 class="menu_dp">Menu</h1></li> <li class="toggle-topbar"><a href="#"></a></li> </ul> <section> <ul class="left"> <!--<li class="menu"><a href="?perfil" title="Ver perfil">Perfil</a></li>--> <li class="menu"><a href="?submit-news" title="Publicar notícia MRN">Publicar notícia MRN</a></li> </ul> </section></nav> <hr class="linha"/> <?php echo $message; ?> <!--CONTEUDO--> <div class="row"> <div class="twelve columns"> <form action="#" method="post" onsubmit="return $(this).validate()" name="publish" > <h3 class="n3">Publicar notícia</h3> <div class="publish-content"> <div> <h3 class="n3v4">Categoria</h3> <select name="categoria"> <option value="Autos/Pistas">Autos/Pistas</option> <option value="Autos/Ralis-TT">Autos/Ralis-TT</option> <option value="Motos/Pistas">Motos/Pistas</option> <option value="Motos/Ralis-TT">Motos/Ralis-TT</option> <option value="Outros">Outros</option> <option value="Entrevistas">Entrevistas</option> <option value="ci">C&I: OnTheRoad</option> <option value="Multimedia">Multimédia</option> </select> </div> <br/> <div> <h3 class="n3v4">Categoria 2 (opcional)</h3> <select name="categoria2"> <option value="">Nenhuma</option> <option value="Autos/Pistas">Autos/Pistas</option> <option value="Autos/Ralis-TT">Autos/Ralis-TT</option> <option value="Motos/Pistas">Motos/Pistas</option> <option value="Motos/Ralis-TT">Motos/Ralis-TT</option> <option value="Outros">Outros</option> <option value="Entrevistas">Entrevistas</option> <option value="ci">C&I: OnTheRoad</option> <option value="Multimedia">Multimédia</option> </select> </div> <br/> <h3 class="n3v4">Destaque?</h3> <label class="cbox"> <input type="radio" name="destaque" value="sim" checked>Sim</input> <input type="radio" name="destaque" value="não">Não</input> </label> <br/> <h3 class="n3v4">Publicar já?</h3> <label class="cbox"> <input type="radio" name="publicado" value="sim" checked>Sim</input> <input type="radio" name="publicado" value="não">Não</input> </label> <br/> <input name="news_title" type="text" class="title" placeholder="(título)" data-validation="required" title="required"/> <input name="news_subtitle" type="text" class="title" placeholder="(subtítulo)" data-validation="required" /> <input name="news_desc" type="text" class="description" placeholder="(descrição)" data-validation="required" title="required" maxlength="165"/> <textarea name="news_post" type="text" class="post" placeholder="(notícia)" data-validation="required" title="required" ></textarea> <input name="news_date" type="text" class="date" placeholder="(data)" data-validation="required" title="required" id="datepicker" /> <input name="hour" type="text" class="description" placeholder="(hora HH:MM)" data-validation="required" title="required" maxlength="5" data-format="hh:mm:ss" id="datetimepicker3" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> <input name="news_image" type="text" class="description" placeholder="(imagem homepage)" data-validation="required" title="required"/> <input name="news_image" type="text" class="description" placeholder="(imagem main)" data-validation="required" title="required"/> <input name="news_image_peq" type="text" class="description" placeholder="(imagem pequena)" data-validation="required" title="required"/> <input name="copyright" type="text" class="description" placeholder="(Copyright da/s Imagem/ns)" data-validation="required" title="required"/></div> <div class="publish-footer"> <input type="submit" name="publish-p" value="Publicar" class="button"> <input type="submit" name="cancel" value="Cancelar" class="secondary button" onclick="window.location='../login/?submit-news'" > </div> </form> </div> </div> <?php include ("rodape.php") ?> <!--SCRIPTS--> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(function() { $( "#datepicker" ).datepicker({ changeYear: true, dateFormat: "dd'-'mm'-'yy", showButtonPanel: true, }); }); </script> <!-- script para Toogle Menu --> <script src="../js/toogle-menu.js"></script> <script type="text/javascript"> tinymce.init({ selector: "textarea", plugins: [ "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker", "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", "save table contextmenu directionality emoticons template textcolor colorpicker", "paste" ], image_advtab: true, font_size_style_values: "9px,10px,11px,12px,13px,14px,16px,18px,20px", toolbar1: "sizeselect | bold italic | insertfile undo redo | styleselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media",//used font size for showing font size toolbar toolbar2: "fontselect | fontsizeselect | colorpicker",//used font size for showing font size toolbar style_formats: [ {title: 'Bold text', inline: 'b'}, {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}}, {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}}, {title: 'Example 1', inline: 'span', classes: 'example1'}, {title: 'Example 2', inline: 'span', classes: 'example2'}, {title: 'Table styles'}, {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'} ], resize: false, inline_styles : true, }); </script> </body> </html> Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/287070-upload-images-php-mysql/#findComment-1473184 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.