2013-08-13 4 views
-4

lorsque l'utilisateur télécharger l'image ou le doc. L'image ou le document ne sont pas stockés dans le dossier de téléchargement, mais les champs restants sont correctement insérés dans la base de données. Je veux le stocker dans le dossier de téléchargement.Comment télécharger le fichier image dans php

+0

au moins un peu de code – KyleK

+0

Cette question est impossible de vous aider sans voir le code effectuant la télécharger. S'il vous plaît le modifier dans votre message. À une conjecture, vérifiez les autorisations de fichiers sur le dossier en cours de téléchargement. –

+0

Plusieurs excellents didacticiels existent à ce sujet: http://www.w3schools.com/php/php_file_upload.asp – Vulcan

Répondre

0

S'il vous plaît voir

if(isset($_REQUEST['submit'])){ 
$file=$_FILES['myfile']['name']; 
$path="PATH YOUR DIRECTORY"; 

if(move_uploaded_file($_FILES['myfile']['tmp_name'],$path.$file)) 
{ 
    echo "FILE UPLOAD SUCCESSFULLY"; 
} 
else{ 
    echo "FAILED"; 
} 

}

En utilisant enctype dans votre <forme> attribut sinon votre fichier ne téléchargeant sur votre serveur.

enctype="multipart/form-data" 

Code HTML

<form method="post" enctype="multipart/form-data"> 
File: <input type="file" name="myfile" /> 
<input type="submit" name="submit" value="Upload" /> 
</form> 

plus d'informations, visitez

http://www.learnphp.in/mypage_6_File-uploading-with-PHP.html

+0

merci pour la réponse chinamy sahu.iam en essayant votre code..image est télécharger avec succès son ok..mai un autre doute quand je inséré dans le code ci-dessus dans la forme comme . image n'est pas upload.that est le problème.vous me dire votre adresse mail je vais envoyer mon code chinmay shau – user2615543

+0

chinmay235 @ gmail. com envoyez-moi avec description ce que vous voulez. – Chinmay235

+0

je vous remercie pour la réponse rapide chimamay j'avais envoyé mon code dans votre adresse e-mail chinmay vérifier. – user2615543

0
public function uploadImage() 
{ 
    //define a maxim size for the uploaded images in Kb 
    define ("MAX_SIZE","1000"); 


    //checks if the form has been submitted 
    if(isset($_POST['picture'])) 
    { 
     //reads the name of the file the user submitted for uploading 
     $image=$_FILES['file']['name']; 
     if ($_FILES["file"]["error"] > 0) 
     { 
      $this->errorMsg = $_FILES["file"]["error"] . "<br />"; 
      $this->errors = 1; 
     } 

     //if it is not empty 

     //get the original name of the file from the clients machine 
     $filename = stripslashes($_FILES['file']['name']); 

     //get the extension of the file in a lower case format 
     $extension = $this->getExtension($filename); 

     $extension = strtolower($extension); 
     //if it is not a known extension, we 
     //will suppose it is an error and will not upload the file, 
     //otherwise we will do more tests 
     if (($extension != "jpg") && ($extension != "jpeg") && 
       ($extension != "png") && ($extension != "gif")) 
     { 
      //print error message 
      $this->errorMsg = "You must choose a jpeg, jpg, 
      png, or gif file"; 
      $this->errors=1; 
     } else { 
     //get the size of the image in bytes 
     //$_FILES['image']['tmp_name'] is the temporary filename of the        file 
     //in which the uploaded file was stored on the server 
     $size=filesize($_FILES['file']['tmp_name']); 

     //Store the extension for listing in session 
     $_SESSION["image_ext"] = $extension; 

     //compare the size with the maxim size 
     //we defined and print error if bigger 
     if ($size > MAX_SIZE*1024) 
     { 
      $this->errorMsg = "You have exceeded the size limit."; 
      $this->errors=1; 
     } 


     //we will give an unique name, 
        //for example the time in unix time format 
     $image_name= $item_num.'.'.$extension; 

     chdir("/home/public_html/"); 
     try { 
     @mkdir($item_num, 0755); 
     chmod($item_num, 0755); 
     } catch (Exception $e) { 

     } 

     //we verify if the image has been uploaded, and print error instead 
     $imagePath = $_FILES['file']['tmp_name']; 

     //the new name will be containing the full 
        //path where will be stored (images folder) 
     $newname= $item_num."/".$image_name; 

     $copied = copy($imagePath, $newname); 
     //Now use that directory andmake the image 

     if (!$copied) 
     { 
     echo "Failure"; 
     $this->errorMsg = "There was an error uploading your image."; 
     $this->errors=1; 
     } 

    } 
    //If no errors registred, print the success message 
    if(isset($_POST['picture']) && !$this->errors) 
    { 
         echo "success"; 
      } 
     } 
Questions connexes