Jump to content

Recommended Posts

Ok.. here is my problem.. i need some advice.

 

The user enters their username and password..and selects a photo to upload. It also checks to make sure there is no duplicate photo name. I want to do a couple more things.. First I would like to redirect to another page after the main upload and insert process is completed. Also, I would like to just rename to the file before uploading.

 

Any ideas?

 

<?php

if(isset($_POST['submit'])) {

$dir = "/home/content/n/w/c/nwclark/html/jmi2/secure/idphotos/"; //Upload directory
$error = ""; //Setting a false error
$address = "http://97.74.52.5/jmi2/".$_SERVER['HTTP_HOST']."/"; //Getting the web address
$username=$_POST['username'];
$password=$_POST['password'];
$file_name = $_FILES['file']['name']; //Getting the file name
$file_type = $_FILES['file']['type']; //Getting the file type
$file_size = "".$_FILES['file']['size']." bytes"; //Getting the file size
$file_tmp = $_FILES['file']['tmp_name']; //Setting the temporary name
$file_address = $address.$dir.$file_name; //URL of file
?>
  <?
mysql_query("INSERT INTO jmi10.user (username,photo,password) VALUES ('$username', '$file_name', '$password')") or die("Error: " . mysql_error());


if(file_exists($dir.$file_name)) {
$error = "<br />Error: A file with the same name already exists!";
}

else {
@copy ($file_tmp, $dir.$file_name) or ($error="<br />Error: File could not
be copied!");
}

if($error != "") {
echo $error;
}

else {
echo "<br />File successfully uploaded!\n";
echo "<br />Name: ".$file_name."\n";
echo "<br />Size: ".$file_size."\n";
echo "<br />Type: ".$file_type."\n";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/161956-help-please/
Share on other sites

First I would like to redirect to another page after the main upload and insert process is completed.

 

header

 

Also, I would like to just rename to the file before uploading.

 

Modify this code to rename your file:

 

$file_name = $_FILES['file']['name']; //Getting the file name

Link to comment
https://forums.phpfreaks.com/topic/161956-help-please/#findComment-854542
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.