PHP image upload and rename script not working

Links for php scripts

Moderators: macek, egami, gesf

ReubenDog
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.

<?php
$host="";
$username="";
$password="";
$db_name="mysql";
$tbl_name="yearbook";

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;
$fileUpload=$new_file_name;
if($fileUpload){
if(copy($_FILES['fileUpload']['tmp_name'], $path)){
}else{
echo "Error";
}
}
$fName=$_POST['fName'];
$mName=$_POST['mName'];
$lName=$_POST['lName'];
$chapter=$_POST['chapter'];
$year1=$_POST['year1'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$email=$_POST['email'];
$month=$_POST['month'];
$year2=$_POST['year2'];
$business=$_POST['business'];
$title=$_POST['title'];
$skills=$_POST['skills'];
$interests=$_POST['interests'];

$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>
<?php

}else{

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

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest