PHP image upload and rename script not working

Links for php scripts

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat Nov 05, 2011 1:38 pm

PHP image upload and rename script not working

Postby ReubenDog » Sun Nov 06, 2011 6:08 pm

Hello, I'm fairly new to PHP and the web classes that I took in school touched very lightly on the subject, but nothing really in depth. I have a new client who's site is incorporating some really complex PHP scripting (well at least to me anyway). He requires a script that will take an uploaded image from a form, rename it then move the file with the new name to a corresponding folder. Below I have a script that seems to work on a Mac at my school with a Linux server, but doesn't seem to work on my Windows PC at the office with a XAMPP test server nor on my clients hosting server which is a Windows server (go figure). If someone can please help me out it would be greatly appreciated and thank you in advance. If the form is required to try and troubleshoot this problem please let me know and I'll provide it to you.

//host, username, and password are missing for security purposes.


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$ftype = $_FILES['fileUpload']['type'];
if (($ftype=="image/jpeg")||($ftype=="image/tiff")||($ftype=="image/gif")){
$file_name = $_FILES['fileUpload']['name'];
$new_file_name=$_POST['fName'].' '.$_POST['mName'].' '.$_POST['lName'].' | '.$file_name;

$path= "uploads/yearBookImages/".$new_file_name;
if(copy($_FILES['fileUpload']['tmp_name'], $path)){
echo "Error";

$insert = "INSERT INTO yearbook (fileUpload, fName, mName, lName, chapter, year1, address, city, state, zip, email, month, year2, business, title, skills, interests)
VALUES ('$fileUpload','$fName','$mName','$lName','$chapter','$year1','$address','$city','$state','$zip','$email','$month','$year2','$business','$title','$skills','$interests')";

$add_yearbook = mysql_query($insert);

<div id="subHeaderText"><small>Yearbook info has been uploaded successfully...</small></div>
<hr />
<div id="subHeaderText" align="right"><small><a href="index.php">Back to home...</a></small></div>


<div id="subHeaderText"><small>Yearbook info was not uploaded successfully. <u>Please double-check the file format type.</u></small></div>

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests