move image file to directory

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

move image file to directory

Post by ninethousandfeet »

hello,

can someone please help me? i've tried to seek help in multiple forums and i've been reading previous posts and as much info as i can online and i am still coming up with the same result: no file added to my directory.
does anyone see what i'm doing wrong? thank you!

Code: Select all

 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
// error array
$error = array();
// define a constant for the maximum upload size
define ('MAX_FILE_SIZE', 51200);
// define constant for upload folder
$uploadDIR = '/home/jhgroup/domains/mysite.com/public_html/upload';
// replace any spaces in original filename with underscores
// at the same time, assign to a simpler variable
$file = $_FILES['image_data']['name'];
str_replace(' ', '_', '/', $file);
$fileTemp = $_FILES['image_data']['tmp_name'];
$randomfilename = sha1($file);
$filename = $randomfilename.$file;
// convert the maximum size to KB
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
// create an array of permitted MIME types
$permitted = array('image_data/gif', 'image_data/jpeg', 'image_data/pjpeg', 'image_data/png');
// begin by assuming the file is unacceptable
$sizeOK = false;
$typeOK = false;
 
// check that file is within the permitted size
if ($_FILES['image_data']['size'] > 0 && $_FILES['image_data']['size'] <= MAX_FILE_SIZE) {
$sizeOK = true;
}
 
// check that file is of a permitted MIME type
foreach ($permitted as $type) {
if ($type == $_FILES['image_data']['type']) {
$typeOK = true;
break;
}
}
 
if ($sizeOK && $typeOK) {
  move_uploaded_file($fileTemp, '$uploadDIR/$filename');
}
 
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: move image file to directory

Post by tech603 »

You may want to talk to your hosting provider and make sure that in the php.ini file your upload temp file is set,
upload_tmp_dir

This setting controls the temporary location of files uploaded with an HTML form. If you don't specify a path for this setting, uploaded files will be temporarily stored in a world-readable location on the server. To protect ease of manipulation and the confidentiality of such files, you should create a directory in your account and specify the new path in your php.ini file:

upload_tmp_dir = /hwxx/daxx/uwnetid/tmp
And if it is set that you have that directory. Without that directory your uploads will go no where.

If all that is set try following this tutorial.

http://www.w3schools.com/PHP/php_file_upload.asp

hope that helps
tanja
Forum Commoner
Posts: 35
Joined: Fri Mar 27, 2009 4:49 am

Re: move image file to directory

Post by tanja »

Thanks for the explanation!
Post Reply