Creare director si adaugare poza

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
Avatar utilizator
evident
Mesaje:168

Creare director si adaugare poza

am dat comanda

Cod: Selectaţi tot

$id = mysql_insert_id();
mkdir("anunt/$id", 0755);
ce comanda trebuie sa dau pentru a adauga o poza la adresa anunturi/$id/numepoza.jpg?
Multumesc

MarPlo Mesaje:4343
Ca sa adaugi poza, in general orice fiser de pe calculator pe server, se foloseste un formular de Upload si cod php cu mai multe comenzi.
Gasesti pe site, la sectiunea scripturi, din cursul PHP-MySQL, un script de upload, sau poti gasi si pe forum subiecte deja discutate, cautand cu casuta "Cautare", de sus.

evident Mesaje:168
azi am incercat sa fac dar tot nu imi iese faza asta...nu stiu unde gresesc...
am asa:insert.php

Cod: Selectaţi tot

<?php
    $con = mysql_connect("localhost","root","12qw23");
    if (!$con)  die('Could not connect: ' . mysql_error());

    mysql_select_db("anunturi", $con);

    if(isset($_POST['titluanunt']) && isset($_POST['nume']) && isset($_POST['categorie']) && isset($_POST['sunteti']) && isset($_POST['textanunt']) && isset($_POST['pret']) && isset($_POST['moneda']) && isset($_POST['email']) && isset($_POST['nrtel']) && isset($_POST['judet']) && isset($_POST['localitate'])) {
      $sql="INSERT INTO anunturi (titluanunt, nume, categorie, sunteti, textanunt, pret, moneda, email, nrtel, judet, localitate)
      VALUES
      ('".$_POST['titluanunt']."','".$_POST['nume']."','".$_POST['categorie']."','".$_POST['sunteti']."','".$_POST['textanunt']."','".$_POST['pret']."','".$_POST['moneda']."','".$_POST['email']."','".$_POST['nrtel']."','".$_POST['judet']."','".$_POST['localitate']."')";

      if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }
      echo include "succes.php";
      $id = mysql_insert_id();
      mkdir("anunt/$id", 0777);

}  
    
    else echo 'Date POST ne primite';
    

    mysql_close($con);
    ?>
Si mai am formular.php

Cod: Selectaţi tot

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #CC0000}
-->
</style>
</head>

<body>
<table width="94%" border="1" align="center">
<form action="insert.php" method="post" enctype="multipart/form-data">
  <tr>
    <td width="16%"><div align="right">Nume de contact: </div></td>
    <td colspan="6"><input type="text" name="nume" />
      Sunteti:
        <input type="radio" name="sunteti" value="Persoana" />
Persoana
<input type="radio" name="sunteti" value="Companie" />
Companie
<label></label>&nbsp;</td>
    </tr>
  <tr>
    <td><div align="right">Categorie Anunt: </div></td>
    <td colspan="6"><select name="categorie">
<option value="Afaceri">Afaceri</option>
<option value="Articole">Articole</option>
<option value="Animale">Animale</option>
<option value="Anticariat">Anticariat</option>
<option value="Arta-Antichitati">Arta si Antichitati</option>
<option value="Auto">Auto</option>
<option value="Calculatoare">Calculatoare</option>
<option value="Colectii">Colectii</option>
<option value="Constructii">Constructii</option>
<option value="Diverse">Diverse</option>
<option value="Donatii">Donatii</option>
<option value="Electrice">Electrice</option>
<option value="Foto">Foto</option>
<option value="Hobby">Hobby</option>
<option value="Imobiliare">Imobiliare</option>
<option value="Locuri-de-munca">Locuri de munca</option>
<option value="Moda">Moda</option>
<option value="Mobilier">Mobilier</option>
<option value="Moto-Velo">Moto Velo</option>
<option value="Media-Publicitate">Media publicitateautolinker.com autolinking image</option>
<option value="Muzica">Muzica</option>
<option value="Pierderi-Gasiri">Pierderi Gasiri</option>
<option value="Servicii">Servicii</option>
<option value="Sport">Sport</option>
<option value="Turism">Turism</option>
<option value="Telefoane">Telefoane</option>

</select>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Titlu Anunt: </div></td>
    <td colspan="6"><input type="text" name="titluanunt" maxlength="87" />&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Text Anunt: </div></td>
    <td colspan="6"><input type="text" name="textanunt" maxlength="255" />&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Pret:</div></td>
    <td width="19%"><input type="text" name="pret"/>&nbsp;</td>
    <td width="11%">(<span class="style1">doar numere</span>) </td>
    <td width="7%"><div align="right">Moneda:</div></td>
    <td colspan="3"><select name="moneda">
<option value="RON">RON</option>
<option value="EUR">EUR</option>
<option value="USD">USD</option>

</select></td>
    </tr>
  <tr>
    <td><div align="right">Adresa e-mail:</div></td>
    <td colspan="6"><input type="text" name="email"/>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Numar de telefon:</div></td>
    <td colspan="6"><input type="text" name="nrtel"/>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Judet:</div></td>
    <td colspan="6"><select name="judet">
<option value="Alba">Alba</option>
<option value="Arad">Arad</option>
<option value="Arges">Arges</option>
<option value="Bacau">Bacau</option>
<option value="Bihor">Bihor</option>
<option value="Bistrita-Nasaud">Bistrita-Nasaud</option>
<option value="Botosani">Botosani</option>
<option value="Braila">Braila</option>
<option value="Brasov">Brasov</option>
<option value="Buzau">Buzau</option>
<option value="Calarasi">Calarasi</option>
<option value="Caras-Severin">Caras-Severin</option>
<option value="Cluj">Cluj</option>
<option value="Constanta">Constansa</option>
<option value="Covasna">Covasna</option>
<option value="Dâmbovita">Dâmbovita</option>
<option value="Dolj">Dolj</option>
<option value="Galati">Galati</option>
<option value="Giurgiu">Giurgiu</option>
<option value="Gorj">Gorj</option>
<option value="Harghita">Harghita</option>
<option value="Hunedoara">Hunedoara</option>
<option value="Ialomita">Ialomita</option>
<option value="Iasi">Iasi</option>
<option value="Ilfov">Ilfov</option>
<option value="Maramures">Maramures</option>
<option value="Mehedinti">Mehedinti</option>
<option value="Mures">Mures</option>
<option value="Neamt">Neamt</option>
<option value="Olt">Olt</option>
<option value="Prahova">Prahova</option>
<option value="Salaj">Salaj</option>
<option value="Satu Mare">Satu Mare</option>
<option value="Sibiu">Sibiu</option>
<option value="Suceava">Suceava</option>
<option value="Teleorman">Teleorman</option>
<option value="Timis">Timis</option>
<option value="Tulcea">Tulcea</option>
<option value="Vaslui">Vaslui</option>
<option value="Vâlcea">Vâlcea</option>
<option value="Vrancea">Vrancea</option>
</select>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right">Localitate:</div></td>
    <td colspan="6"><input type="text" name="localitate"/>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td colspan="6">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="6"><input type="submit" name="Submit2" value="Submit" /></td>
  </tr>
  </form>
</table>

</body>
</html>
- Aveai un script aici cu inregistrare.cand se inregistra cineva trebuia sa bage si poza.nu mai stiu unde era.

MarPlo Mesaje:4343
Prea mult cod de verificat, iti spun doar principiu ce trebuie si link de unde sa te inspiri.
Pentru a incarca un fisier intr-un director cu PHP, formularul trebuie sa contina un camp Input de tip "file" ( <input type="file" name="nume_camp" /> ).
In php se preia diferit datele din acest camp (cu $_FILES['nume_camp']['name']).
Ca sa copie fisierul pe server se foloseste functia move_uploaded_file(). Gasesti pe net mai multe articole despre acestea, sau mai bine descarci scriptul de aici Script upload si-l studiezi, are explicatii detaliate, in romana, pentru cine vrea sa invete.

- Scriptul de inregistrare, cu adaugare poza, e la pagina: Script Utilizatori.

evident Mesaje:168
am reusit:)
am facut oarecum babeste dar merge:D
imi face directoru si imi baga si poza pe care eu o uploadez:)
daca doreste cineva scriptul pm
Multumesc

Subiecte similare