Hello everybody. There is a form and a script that add the entered information to the database. How can I add the function of uploading a file to the server to this code, and write its relative path to the database in the img field of the news table, so that the link would be "/img/news/%filename%.jpg"

<form action="save_news.php" method="post" name="news"> <table border="1" cellpadding="0" cellspacing="0" width="350"> <tr> <td colspan="2" align="center" height="50px"><strong>Отправка запроса</strong></td> </tr> <tr> <td width="150" height="50px" align=center>Тема новости :</td> <td align=center><input type="text" name="title" maxlength="30" /></td> </tr> <tr> <td width="150" height="50px" align=center>Текст новости :</td> <td align=center><textarea name="text"></textarea></td> </tr> <tr> <td width="150" height="50px" align=center>Автор новости :</td> <td align=center><input type="text" name="author" maxlength="30" /></td> </tr> <tr> <td width="150" height="50px" align=center>Изображение новости:</td> <td align=center><input type="text" name="img" /></td> </tr> <tr> <td colspan="2" align="center" height="50px"> <input type="submit" class="buttons" value="Отправить запрос" /> <input type="reset" class="buttons" value="Очистить" /> </td> </tr> </table> </form> <? include('../script/config.php'); $cdate = date("Ymd"); $query = "INSERT INTO news SET title='".$_POST['title']."', text='".$_POST["text"]."', author='".$_POST["author"]."',date='$cdate', img=".$_POST["img"].""; } mysql_query($query) or die(mysql_error()); mysql_close(); echo ("<div style=\"text-align: center; margin-top: 10px;\"> <font color=\"green\">Данные успешно сохранены!</font> <a href=\"news.php\">Вернуться назад</a></div>"); ?> 

    1 answer 1

    Have you tried to ask Google? The question has been asked thousands of times, thousands of articles about this.

    http://php.su/phphttp/?uploads

    http://softtime.ru/scripts/upload.php

    http://www.php.ru/manual/features.file-upload.html

    http://freehost.com.ua/faq/buleten/article/article_id/6

    http://phpclub.ru/detail/article/upload

    http://www.webnotes.com.ua/index.php/archives/114

    http://sites.znu.edu.ua/webprog/001-lect/020-php/0223-php-forms/003-file-upload.lect

    http://docstore.mik.ua/manuals/php/ru/features.file-upload.html

    B is links from the first page of Google, isn’t it so difficult to search for information yourself ?! http://www.google.com.ua/search?aq=f&sourceid=chrome&ie=UTF-8&q=%D0% B7% D0% B0% D0% B3% D1 %80% D1% 83% D0% B7% D0 % BA% D0% B0 +% D1% 84% D0% B0% D0% B9% D0% BB% D0% BE% D0% B2 + php

    • Yes, this is understandable, no article gives an example of uploading the path and name of the final file to the database. Got already :( - CryFiX
    • one
      oh god .. you watched examples of file downloads? there everything is painted $ _FILES ['uploadfile'] ['name'] - the file name before sending it to the server, for example, pict.gif; re-read at least one of the articles and articles that I have brought above should not be any - Elime