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

Links for php scripts

Moderators: macek, egami, gesf

k9tsu
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Sep 22, 2012 10:04 am

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

Postby k9tsu » Sat Sep 22, 2012 10:09 am

Hello! I'm running www.northernilskywarn.org

Basically, See that "Net Status" Icon that flashes (It's a GIF file) on the left? When we change out net status, I want it to be easy for the 3 "website operators" I have to log into the admin control page (Yes, I have it pass/user protected) and have a drop down menu, or similar, that says "Change Net Status" then 4 options: Blue, Green, Yellow, and Red. The path to the "net staus icons" are /images/CAL.gif. (CAL meaning condition alert level.)

Right now, I have a template set on the pages in Dreamweaver that always draws up the /images/CAL.gif image to display. What I have had to do was go thru Filezilla, change the name of what GIF I want displayed. That isn't productive, especially for other website operators without the ability to FTP.

I was thinking a way to copy one of those images, move it to a "current status" directory, and rename it to "current.gif" or something. Then, when the admin changes it from, say, blue to yellow, it moves "yellow.gif" into the " current status" directory and names it "current.gif" and gets rid of the one in there already.

If anyone knows how to set this up, I'm stupid when it comes to FTP so I need "step by step."

THANKS!!

dering
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Sep 18, 2012 5:59 am

Re: How can I allow users to change an image on my site usin

Postby dering » 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 . ' ';
chdir("uploads");
mkdir($_POST["savedLogin"],0777);
chdir($_POST["savedLogin"]);

$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';
}
else
foreach ($errors as $error) echo $error, '<br />';

k9tsu
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Sep 22, 2012 10:04 am

Re: How can I allow users to change an image on my site usin

Postby k9tsu » Sun Sep 23, 2012 2:02 pm

The last sentence in my post should have said "I am stupid with PHP." Not, FTP. Haha.

Thanks for posting that! I appriciate it! However, I was hoping for maybe a way to just "move" or "rename" a the files so admins don't have to always upload a new image.

Thanks!


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests