AHMED SAMY
asked on
problem in upload images
i need to upload 9 images
this code is responsible for uploading all images
it works good but i have to problems :
1- slow page don't know why.
2- upload only 6 images not 9 and show error
error on page :
products.php
script.js
this code is responsible for uploading all images
it works good but i have to problems :
1- slow page don't know why.
2- upload only 6 images not 9 and show error
// file vars
$path=$_FILES['products/']['tmp_name'];
$name=$_FILES['products/']['name'];
$size=$_FILES['products/']['size'];
$type=$_FILES['products/']['type'];
$error=$_FILES['products/']['error'];
$j = 0; //Variable for indexing uploaded image
$target_path = "products/"; //Declaring Path for uploaded images
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array
$validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed
$ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.)
$file_extension = end($ext); //store extensions in the variable
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];//set the target path with a new name of image
$j = $j + 1;//increment the number of uploaded images according to the files in array
if (($_FILES["file"]["size"][$i] < 200000) //Approx. 200kb files can be uploaded.
&& in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder
$sqlimage="INSERT INTO products_images (image_name,product_id) VALUES ('$target_path','$product_id')";
$queryimage=mysqli_query($conn,$sqlimage);
echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
} else {//if file was not moved.
echo $j. ').<span id="error">please try again!.</span><br/><br/>';
}
} else {//if file size and file type was incorrect.
echo $j. ').<span id="error">***Invalid file Size (max 200kb) or Type (jpeg , jpg , png) ***</span><br/><br/>';
}
}
error on page :
1).Image uploaded successfully!.
2).Image uploaded successfully!.
3).Image uploaded successfully!.
4).Image uploaded successfully!.
5).Image uploaded successfully!.
6).Image uploaded successfully!.
Warning: move_uploaded_file(products/33b4179f8d76512f1a5fed14a0b8dfe0.jpgc949c46f9f94775d53ff1534a86f104d.jpg5fc3c7df9a6cc7485b31b06565ecb7f8.jpgb8a6e017c80539f138b97460d2649062.jpg61a6bdfb3732de16c90cd6c31d3b0289.jpg234c4ae6600450b57fc2bd143a7a98e9.jpg0d00018388fb3c8489743237544aa42f.jpg): failed to open stream: Invalid argument in C:\AppServ\www\*****\admin\addproducts.php on line 86
Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php9FED.tmp' to 'products/33b4179f8d76512f1a5fed14a0b8dfe0.jpgc949c46f9f94775d53ff1534a86f104d.jpg5fc3c7df9a6cc7485b31b06565ecb7f8.jpgb8a6e017c80539f138b97460d2649062.jpg61a6bdfb3732de16c90cd6c31d3b0289.jpg234c4ae6600450b57fc2bd143a7a98e9.jpg0d00018388fb3c8489743237544aa42f.jpg' in C:\AppServ\www\*****\admin\addproducts.php on line 86
7).please try again!.
Warning: move_uploaded_file(products/33b4179f8d76512f1a5fed14a0b8dfe0.jpgc949c46f9f94775d53ff1534a86f104d.jpg5fc3c7df9a6cc7485b31b06565ecb7f8.jpgb8a6e017c80539f138b97460d2649062.jpg61a6bdfb3732de16c90cd6c31d3b0289.jpg234c4ae6600450b57fc2bd143a7a98e9.jpg0d00018388fb3c8489743237544aa42f.jpg0d00018388fb3c8489743237544aa42f.jpg): failed to open stream: Invalid argument in C:\AppServ\www\******\admin\addproducts.php on line 86
Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php9FEE.tmp' to 'products/33b4179f8d76512f1a5fed14a0b8dfe0.jpgc949c46f9f94775d53ff1534a86f104d.jpg5fc3c7df9a6cc7485b31b06565ecb7f8.jpgb8a6e017c80539f138b97460d2649062.jpg61a6bdfb3732de16c90cd6c31d3b0289.jpg234c4ae6600450b57fc2bd143a7a98e9.jpg0d00018388fb3c8489743237544aa42f.jpg0d00018388fb3c8489743237544aa42f.jpg' in C:\AppServ\www\******\admin\addproducts.php on line 86
8).please try again!.
Warning: move_uploaded_file(products/33b4179f8d76512f1a5fed14a0b8dfe0.jpgc949c46f9f94775d53ff1534a86f104d.jpg5fc3c7df9a6cc7485b31b06565ecb7f8.jpgb8a6e017c80539f138b97460d2649062.jpg61a6bdfb3732de16c90cd6c31d3b0289.jpg234c4ae6600450b57fc2bd143a7a98e9.jpg0d00018388fb3c8489743237544aa42f.jpg0d00018388fb3c8489743237544aa42f.jpgd92b8e24565dc05f596aeedede0105d3.jpg): failed to open stream: Invalid argument in C:\AppServ\www\*****\admin\addproducts.php on line 86
Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php9FEF.tmp' to 'products/33b4179f8d76512f1a5fed14a0b8dfe0.jpgc949c46f9f94775d53ff1534a86f104d.jpg5fc3c7df9a6cc7485b31b06565ecb7f8.jpgb8a6e017c80539f138b97460d2649062.jpg61a6bdfb3732de16c90cd6c31d3b0289.jpg234c4ae6600450b57fc2bd143a7a98e9.jpg0d00018388fb3c8489743237544aa42f.jpg0d00018388fb3c8489743237544aa42f.jpgd92b8e24565dc05f596aeedede0105d3.jpg' in C:\AppServ\www\*******\admin\addproducts.php on line 86
9).please try again!.
addproducts.phpproducts.php
script.js
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks you very much you are very clever man
Thank you and you are most welcome.
Open in new window
after the if condition (between lines 85 and 86) and post the output.