Click to See Complete Forum and Search --> : moveupload


jagguy
11-20-2006, 02:54 AM
Hi,

I am trying to upload a directory of small image files. I have the directory name and an array of filenames to upload. I can't seem to use moveupload as it doesn't work . Here is an example. I didn't want to upload 1 file at a time so I am doing abatch upload if possible.

$file="c:/www/php/imagetest/one33.jpg";
$target_path= "c:/www/php/images2";


if(move_uploaded_file($file, $target_path)) {
echo "<strong>Please enter details for your photo you uploaded as
". ( $filename).
" to be entered into the system</strong>";
} else{.....
//nothing gets uploaded and the error is moveuploaded returned false.

q)Is it possible to uplad multiple images from a directory using php eg just give directory name and all file are upladed like 50 of them?

so_is_this
11-20-2006, 10:00 AM
move_uploaded_file() isn't going to work unless that particular file was actually and currently uploaded via the browser's INPUT TYPE=FILE control element -- i.e., the file name specified must be the temp file name created by PHP during PHP's HTTP POST upload processing. Also, there are no PHP functions which perform operations on all files in a given folder. Any such functions work on a single file at a time and must be executed in a loop in order to process all files in a given folder.

CrazyGaz
11-20-2006, 01:58 PM
q)Is it possible to uplad multiple images from a directory using php eg just give directory name and all file are upladed like 50 of them?

The only way I can think to do this is to create a zip file of the images, then unzip them on the server.

jagguy
11-20-2006, 04:53 PM
q)Without spending hours finding out, can you upload a zip file, read the filenames into an array or something and store them on your server.

q) to install zip on php with winxp, I uncomment the php.ini and goto the extension=php_zip.dll and restart apache.

The I run the this to test it and it fails with error

Fatal error: Cannot instantiate non-existent class: ziparchive in C:\www\php\zip1.html on line 3

Does this mean it is not installed? I did the same process with GD and it worked for that.
<?php

$zip = new ZipArchive();
$filename = "./test112.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>