Jump to content

[SOLVED] Uploading on Localhost


mattal999

Recommended Posts

Hi,

 

Basically, i'm trying to upload a file, say 1.jpg, to a folder using PHP.

 

I am using this:

 

<?php
function is_uploaded_file2($filename) 
{
   if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
       $tmp_file = dirname(tempnam('', ''));
   }
   $tmp_file .= '/' . basename($filename);
   return (ereg_replace('/+', '/', $tmp_file) == $filename);
}
if(isset($_POST))
{
if(is_uploaded_file2($_FILES['mp3']['tmp_name']))
{
if($_FILES['mp3']['type'] == 'audio/mpeg')
{
$files = $_FILES['mp3'];
$tmpname = $files['tmp_name'];
$name = $files['name'];
if(move_uploaded_file($tmpname, 'upload/'.$name))
{

CLIPPED

 

and this works fine on my website when uploaded via FTP to my proper website, but not on localhost.

 

It fails on is_uploaded_file2()

 

Any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/123111-solved-uploading-on-localhost/
Share on other sites

I don't get an error, this runs:

 

echo is_uploaded_file2($_FILES['mp3']['tmp_name']);
?>
<script>
window.parent.document.getElementById("mp3upload").style.display='block';
window.parent.document.getElementById("progress").style.display='none';
window.parent.document.getElementById("donedev").style.display='block';
window.parent.document.getElementById("donedev").innerHTML='The file could not be uploaded!';
</script>

 

And i don't get anything where i put echo "the function".

 

I'm running PHP4

What do you mean by 'it fails on is_uploaded_file2()' ? Do you get any error messages? What actually happens?

 

On a sidenote, this isn't a valid way of checking if the form's been submitted:

 

if(isset($_POST))

 

That will always return true, since the superglobal arrays are always defined, regardless of if there's anything in them or not. Try using:

 

if(count($_POST) > 0)

 

Oh, and it'd really help if you indented your code properly.

As you are running this on a local install edit your php.ini and make sure erroir_reporting is set to E_ALL and display_errors is set to On.

 

Make sure you restart your HTTP server (eg Apache, IIS etc) after modifying the php.ini. If there is any errors in your code they should be displayed during runtime.

 

You may want to post your code in full too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.