How can I allow users to change an image on my site using a

Links for php scripts

Moderators: egami, macek, gesf

Post Reply

Sun Sep 23, 2012 11:17 am

I had this on a form for students to submit their work:

echo 'Project Number (1-16):<input type="text" size="2" maxlength="2" name="project" style="font-size:100%"><br />';
echo '<input type ="file" name = "image" style="font-size:100%"/><br />';
echo '<input name="form_action[upload]" type="submit" value="Upload" style="width:15em;font-size:100%"/><br />';

After they log in, I had students uploading files with some checks using this code:

//make sure the user has a directory available
$dir = '/uploads/' . $_POST["savedLogin"];
echo '~';
echo $dir . ' ';

$errors = array();
$allowed_ext = array('jpg', 'jpeg', 'png','gif','doc','docx','dotx','xls','xlsx','xltx','xlsb','ppt','pptx','potx','accdb','accde','accdt','sldx','htm','html','wps','mht','mhtml');
$file_name = $_FILES['image']['name'];
$file_ext = strtolower(end(explode('.',$file_name)));
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
if (in_array($file_ext,$allowed_ext) === false) $errors[] = 'uploaded file extension not allowed';
if ($file_size > 110000000) $errors[] = 'file size must be under 100mbs';
if (($Project > 16) || ($Project < 1)) $errors[] = 'project number must be from 1 to 16 *' .$Project.'*';
if (empty($file_name))$errors[] = 'no file name';
if (empty($errors))
if (move_uploaded_file($file_tmp, $Project . '.' .$file_ext))echo 'file uploaded';
foreach ($errors as $error) echo $error, '<br />';

Post Reply