اذهب إلى المحتوى
  • 0

رفع الصور إلى المجلد ب PHP

Shamma Mohammed

السؤال

السلام عليكم  

عندي مشكلة جربت الكثير من اكواد تحميل الصوره الى مجلد في الجهاز لاكن لم يضبط اي كود منهم  هل لنظام ماك طريقة خاصة ؟

استخدم XAMPP 

الكود :

<?php
error_reporting(0);
?>
<?php
$host = "localhost:3306";
$dbUsername = "root";
$dbPassword = "";
$dbname = "photos";

$db = mysqli_connect($host, $dbUsername, $dbPassword, $dbname);

if (!$db) {
    die("Connection failed: " .mysqli_connect_error());
}
$msg = "";

// If upload button is clicked ...
if (isset($_POST['upload']) && isset($_FILES['uploadfile'])){
  $category=$_POST['category'];
  $img_name = $_FILES['uploadfile']['name'];      //getting user uploaded name
  $img_type = $_FILES['uploadfile']['type'];       //getting user uploaded img type
  $tmp_name = $_FILES['uploadfile']['tmp_name'];   //this temporary name is used to save/move file in our folder.

                   // let's explode image and get the last name(extension) like jpg, png
  $img_explode = explode(".",$img_name);
 $img_ext = end($img_explode);   //here we get the extension of an user uploaded img file

   $extension= ['png','jpeg','jpg','gif'];
   // Get the name of images
   	$Get_image_name = $_FILES['uploadfile']['name'];

   	// image Path
   	$image_Path = "sora/".basename($Get_image_name);

   	$sql = "INSERT INTO image (filename, category) VALUES ('$Get_image_name', '$category')";

 	// Run SQL query
   	mysqli_query($db, $sql);

  	if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $image_Path)) {
		echo "Your Image uploaded successfully";
	}else{
		echo  "Not Insert Image";
	}

   }







	?>


<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>


<form method="POST" action="" enctype="multipart/form-data">
  <table>
    <tr>
      <td>Theme image</td>
  <td>	<input type="file" name="uploadfile" value=""/>   </td>
</tr>
  <tr>
    <td>Theme category</td>
    <td>
      <select name="category">
        <option value="">...</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
      </select>
    </td>
  </tr>
<tr>
	  <td>	<button type="submit" name="upload">UPLOAD</button>  </td>
</tr>
</table>
</form>

</body>
</html>

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

من الممكن أن يكون السبب في ذلك هو مسار الصور, جرب أن تكتب المصار بالشكل التالي

$_SERVER['DOCUMENT_ROOT']."المسار بالنسبة لمجلد الhtdocs"

حيث أن العنصر DOCUMENT_ROOT في المصفوفة $_SERVER تحتوي على المسار الخاص بالخادم

إن لم يعمل برجاء التأكد من الصﻻحيات 

يمكنك التأكد من أن المشكلة ليست من الصﻻحيات عن طريق الذهاب إلى مجلد الصور وتقوم بالتالي

file > Right click > Get info 

ومن ثم جعل الصﻻحيات read&write ومن ثم تجربة الملف مرة أخرى

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...