-1

i have a problem with uploading images into different directory.

$path = "../uploads/";
$path2 = "../uploads2/";
$imagename = $_FILES['photoimg']['name'];
$actual_image_name = $imagename;
$uploadedfile = $_FILES['photoimg']['tmp_name'];


$widthArray = array(600,240); //resize width.
foreach($widthArray as $newwidth)
{
  $filename = $uploadedfile,$path,$actual_image_name,$newwidth;

//Original Image
if(move_uploaded_file($uploadedfile, $path.$actual_image_name))
{}

if(move_uploaded_file($uploadedfile, $path2.$actual_image_name))
{}

i want to upload image into uploads and uploads2 folders also?

for example width width = 600px into uploads, width = 240px into folder upload2.

what's wrong with my code?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ching Ching
  • 217
  • 1
  • 5
  • 15

2 Answers2

2

After moving the file with move_uploaded_file it isn't available in the location stored in $uploadedfile anymore. For the second file you have to use copy function.

Please try the following:

if(move_uploaded_file($uploadedfile, $path.$actual_image_name))
{}

if(copy($path.$actual_image_name, $path2.$actual_image_name))
{}
mario.van.zadel
  • 2,919
  • 14
  • 23
0

Remove this line. I don't know for what purpose it's there.

$filename = $uploadedfile,$path,$actual_image_name,$newwidth;

To resize the uploaded image use any library to resize it then pass it. But here is the full code to upload in different directory. But you will have to resize these two $file1 & $file2 to your expected resize file and replace the same in $file1 & $file2 To resize you can use any code suggested here

    $path1 = "../uploads/";
    $path2 = "../uploads2/";
    $file1= $_FILES['photoimg'];
    $file2= $_FILES['photoimg'];

    $file1_imagename = $file1['name'];
    $file2_imagename = $file2['name'];

    $file1_actual_image_name = $file1_imagename;
    $file2_actual_image_name = $file2_imagename;

    $file1_uploadedfile = $file1['tmp_name'];
    $file2_uploadedfile = $file2['tmp_name'];


    $widthArray = array(600, 240); //resize width.

    if (move_uploaded_file($file1_uploadedfile, $path1 . $file1_actual_image_name)) {
        echo "Uploaded Successfully!";
    }

    if (move_uploaded_file($file2_uploadedfile, $path2 . $file2_actual_image_name)) {
        echo "Uploaded Successfully!";
    }
Community
  • 1
  • 1
Ahmad Asjad
  • 825
  • 1
  • 8
  • 29